You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imagine you have a channel that should be joined and left upon chat open/close in UI. If we open & close & open the chat, it should create channel 1, close channel 1, create channel 2 with the same topic (not 1 because 1 should be closed at this point).
The callback above is discarded before phoenix has a chance to call it after channel process termination on server, which causes the closed channel to stay in socket.channels with leaving state instead of being removed from there. This makes findChannel being able to find this "zombie" channel instead of creating a new one -> we attach to "zombie" channel in handleJoin instead of creating a new one.
I see the reasoning behind these off calls, I don't have the exact repro for the described use case below, but perhaps we could use channel.off(event, ref) instead of channel.off(event) to fix the issue with "error"?
Tbh, I believe the solution with .off/1 or .off/2 on errored channels is not robust and might lead to other issues. I do not have good ideas now, but perhaps it'd be better to find a reasonable way to leave / remove these channels from socket.channels on client side instead of allowing them to stay there forever. I understand that the lib cannot decide if client actually wants this behavior, so maybe it's indeed the job of the client to correctly call leave?
The text was updated successfully, but these errors were encountered:
Hey thanks for the write up. With the current logic, I'm able to join -> leave -> join a channel, and I don't see the previous channel in with state: 'leaving' inside socket.channels.
For reproing, the easiest way is to have some channel like room:id and then connect on the frontend with a bad id, such that the server responds with {:error, message}. Then without calling leave on the frontend, connect to room:id with a good id.
After a moment, you will see a join attempt on that previous bad id and the hook state should update to it's error state since it recieved the error again from that first channel.
I think there is a more elegant solution for sure, but this did seem to work and fit into the "react" way of doing things, where the topic is driving the state of the hook.
If it's causing trouble, im open to removing the logic and then putting it on the dev to leave the channel. Although, if a dev wrote code where the topic in a mounted useChannel changes, I feel like it's clear they want this channel to leave the previous topic. What are your thoughts?
I've not figured out a solution for this yet, but the following code breaks phoenix.js channel closing logic:
use-phoenix/src/useChannel/useChannel.ts
Lines 172 to 174 in 57e8218
_channel.off
discards all registered callbacks, including the internal one fromphoenix
:https://github.com/phoenixframework/phoenix/blob/092605f4c3696c4bfe3a531b024030090c1ea23b/assets/js/phoenix/channel.js#L49-L54
Imagine you have a channel that should be joined and left upon chat open/close in UI. If we open & close & open the chat, it should create channel 1, close channel 1, create channel 2 with the same topic (not 1 because 1 should be closed at this point).
The callback above is discarded before phoenix has a chance to call it after channel process termination on server, which causes the closed channel to stay in
socket.channels
withleaving
state instead of being removed from there. This makesfindChannel
being able to find this "zombie" channel instead of creating a new one -> we attach to "zombie" channel inhandleJoin
instead of creating a new one.use-phoenix/src/useChannel/useChannel.ts
Lines 90 to 91 in 57e8218
I see the reasoning behind these
off
calls, I don't have the exact repro for the described use case below, but perhaps we could usechannel.off(event, ref)
instead ofchannel.off(event)
to fix the issue with "error"?use-phoenix/src/useChannel/useChannel.ts
Lines 144 to 174 in 57e8218
Tbh, I believe the solution with
.off/1
or.off/2
on errored channels is not robust and might lead to other issues. I do not have good ideas now, but perhaps it'd be better to find a reasonable way to leave / remove these channels fromsocket.channels
on client side instead of allowing them to stay there forever. I understand that the lib cannot decide if client actually wants this behavior, so maybe it's indeed the job of the client to correctly callleave
?The text was updated successfully, but these errors were encountered: