Skip to content
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

WebSocket not disconnecting when detached #31

Open
SillyMoo opened this issue Mar 6, 2018 · 3 comments
Open

WebSocket not disconnecting when detached #31

SillyMoo opened this issue Mar 6, 2018 · 3 comments

Comments

@SillyMoo
Copy link

SillyMoo commented Mar 6, 2018

When a WebSocket head is disconnected, the websocket remains open. This is a problem if you have a long lived websocket and wish to change behaviour by swapping between heads.
It might be good to provide an option to allow disconnection when detached. I am happy to provide a PR for this issue if accepted.

@emanchado
Copy link
Contributor

Thanks for the bug report!

Hm, if I understand the code correctly, that's not something you can do automatically because in principle there's no reference to the open socket in the head. Also, there could be several sockets! So it seems to me that the best solution would be to expose a way to run code when the head is detached. At least for RoboHydraWebSocketHeads. What did you have in mind? This? Something else?

Are you thinking of redefining the detach method for RoboHydraWebSocketHead and call some head property (eg. this.onDetach) if it was defined on head creation?

@SillyMoo
Copy link
Author

Sorry for the delay in responding, I got distracted :) So there is a reference to the socket inside the handler function in the head. So the solution I am using at the moment is to add a detach() method from inside the handler, which detaches the socket.
Obviously I had however forgotten that there can be >1 socket (I'm testing a client so only have 1 socket open at a time). But I see no reason you could not keep a list of sockets and close them on detach.
I do however like the idea of an onDetach property/event, makes things more flexible (and presumably the WebSocketProxy would by default detach as you would not usually expect folks to extend the proxy?).

@emanchado
Copy link
Contributor

Yeah, that probably makes sense. Are you going to prepare a PR? I'm a bit scared about potentially breaking tests (by changing the default behaviour), but the chances are probably ridiculously low, so I'm guessing we're fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants