-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Realtime - Subscribing to the same channel id causes upstream closes / unexpected behavior. #818
Comments
Well, you are trying to subscribe to the same channel multiple times with a single Supabase Client. Each new channel overrides to old one, that's how the subscriptions work: supabase-kt/Realtime/src/commonMain/kotlin/io/github/jan/supabase/realtime/RealtimeImpl.kt Lines 237 to 240 in 8117c62
That explains this, different ids means they don't override each other. The solution is just to have one client per user/device. So in your example, you would have a new Supabase Client for each user. |
I swapped out the key, the "userId" as exemplified in the docs. If I connect to a new channel under the context of a unique user, I would generally expect it to be keyed based on the <channel_id/topic, user_id> pair. So it's not possible to subscribe to a channel multiple times (as unique users) over a single connection? Channel ids are in a global context, so I didn't expect this behavior. At the very least, it should throw an error instead of allowing itself to do something that is not supported? If it's keyed based on the channel_id / topic, then shouldn't |
Well, the key is only relevant for presences. Generally any realtime messages (broadcasts, db changes, presences) are identified through the topic (which is the channel id) and then sent to channel event handlers. The presence key is not relevant for any client side message identification. (Also not received in any message)
The I can look into making this more clear. |
General Info
Version(s)
3.0.2
Kotlin Target(s) and their respective versions
2.0.21 / JVM 8
What happened? (include your code)
Hey everyone, love the work everyone has done.
I am not sure if I missed some details in the documentation here, or I am misunderstanding how presence works, or this is actually a bug. I tried tinkering around with channels, and tried connecting multiple separate coroutines ("user clients") to some channel, each client represents some user who is interested in the channel (think microservices). I expect it to just work, but it seems when the second user subscribes to the channel, the upstream is sending a close command to the first subscriber. If I understand correctly, channels do not have to be created ahead of time. Given the upstream server seems to be forcing the channel closed, I am a bit confused why. I dug into the Realtime logs, and the only hint I see is: "Tenant has no connected users, database connection will be terminated". Am I restricted from doing some in-process communication on the same channel? (1 channel per client) Do I need to be cautious of where the channel is sourcing from, and avoid subscribing to the channel if it happened to be on the same JVM/Client?
Something to note: If they all subscribe to different channels (ex:
main-$user
instead ofmain
), it works fine.It doesn't seem to be permissions or quota.
Edit: Seems to be indeed 1 channel subscription (by id) per connection. Don't see where this is documented. If this is confirmed the case, perhaps the behavior should be to throw an error when it detects a existing subscription?
Thank you for your time.
Steps To Reproduce (optional)
Run the snippet and you should see none of the "clients" make it past the tracking step.
Relevant log output (optional)
The text was updated successfully, but these errors were encountered: