Skip to content

fix(realtime): subscribed state#2438

Closed
7ttp wants to merge 2 commits into
supabase:masterfrom
7ttp:fix/subscribed
Closed

fix(realtime): subscribed state#2438
7ttp wants to merge 2 commits into
supabase:masterfrom
7ttp:fix/subscribed

Conversation

@7ttp

@7ttp 7ttp commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

TL;DR

Delay SUBSCRIBED only for channels that bind postgres_changes callbacks exclusively
and keep the existing timing for mixed channels

Prob:

SUBSCRIBED could be emitted before the Postgres change feed was actually ready
which made postgres-only channels look ready too early

so now basically, wait for the postgres_changes system ready message before emitting SUBSCRIBED
for postgres-only channels while leaving channels with broadcast or presence callbacks unchanged

ref:

@7ttp 7ttp requested review from a team as code owners June 11, 2026 10:30
@pkg-pr-new

pkg-pr-new Bot commented Jun 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2438

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2438

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2438

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2438

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2438

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2438

commit: 153d8b0

@mandarini

Copy link
Copy Markdown
Contributor

@edgurgel thoughts?

@mandarini mandarini added the realtime-js Related to the realtime-js library. label Jun 12, 2026
@mandarini mandarini requested a review from edgurgel June 12, 2026 12:31
@edgurgel

Copy link
Copy Markdown
Member

Hey team I'm going to play with this branch for some days! Thanks for the PR 🙇

@mandarini

Copy link
Copy Markdown
Contributor

Nice, thanks @edgurgel ! Can you please ping me once you've tested and are ok to merge?

@edgurgel

edgurgel commented Jun 16, 2026

Copy link
Copy Markdown
Member

Hey @7ttp here is my initial feedback:

  • A "normal" join has a timeout that fires if it gets no response from the server. So I think we need a timeout timer here to do something similar. It should use the same timeout we optionally get from subscribe or default to this.socket.timeout
  • We need to handle "status" being not "ok" and set the error state can call the callback etc
  • We need to call this._resetSubscribeState() on _onError and on the happy path as well when we emitSubscribed I think?

@7ttp

7ttp commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Hey @7ttp here is my initial feedback:

* A "normal" join has a timeout that fires if it gets no response from the server. So I think we need a timeout timer here to do something similar. It should use the same timeout we optional get from `subscribe` or default to `this.socket.timeout`

* We need to handle "status" being not "ok" and set the error state can call the callback etc

* We need to call `this._resetSubscribeState()` on `_onError` and on the happy path as well when we `emitSubscribed` I think?

addressed! added the pending system ready timeout....
handled non ok system statuses, and reset the subscribe state on both channel error
& successful subscribed emit :) 💚

edit: QQ: any update on this? 🙂

@edgurgel

Copy link
Copy Markdown
Member

Thanks @7ttp ! Will play with the error states and time outs and get back to you! Looking good so far! <3

@edgurgel

edgurgel commented Jul 1, 2026

Copy link
Copy Markdown
Member

Sorry for the delay!

I've tested with a few error cases and at least one missing thing is:

When there is a timeout a channel with only pg changes does not try to "rejoin" like a normal timeout. So we would need to actually leave the channel and then start a rejoin timer to simulate what a phx_join timeout already cases.

Because this is starting to feel very complicated (and a bit hacky) we discussed with the team and we agreed that we would rather move this to the backend (and option to wait for the subscription on join) and simplify not only this client but all clients.

Appreciate the patience and the help @7ttp. Sorry if we couldn't proceed with this one!

@edgurgel edgurgel closed this Jul 1, 2026
@mandarini

Copy link
Copy Markdown
Contributor

Thank you @edgurgel

@7ttp 7ttp deleted the fix/subscribed branch July 1, 2026 09:31
@7ttp

7ttp commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the delay!

I've tested with a few error cases and at least one missing thing is:

When there is a timeout a channel with only pg changes does not try to "rejoin" like a normal timeout. So we would need to actually leave the channel and then start a rejoin timer to simulate what a phx_join timeout already cases.

Because this is starting to feel very complicated (and a bit hacky) we discussed with the team and we agreed that we would rather move this to the backend (and option to wait for the subscription on join) and simplify not only this client but all clients.

Appreciate the patience and the help @7ttp. Sorry if we couldn't proceed with this one!

makes sense, ty! 🙂💚

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

realtime-js Related to the realtime-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Premature 'SUBSCRIBED' status for postgres_changes signals incorrect readiness

3 participants