-
Notifications
You must be signed in to change notification settings - Fork 36
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
driver.close() before driver.start() should close #8
Conversation
If you decide to open a client connection but then close it before the TCP connection succeeds, the websocket-driver change tested by this commit will ensure that it will actually close, rather than ignoring the close() method. The change to API.close also seems correct to me, though I'm not sure if there are any observable changes if you don't do it.
This is tested by faye/faye-websocket-node#29. |
Another possibility would be to keep this module the same and declare that close before start is an error. Then make a more complex change to faye-websocket-node, something like:
Although I think this would allow for a place where you call |
I've not reviewed these changes by eye yet but I have run them past the Autobahn test suite and there don't seem to be any regressions. |
Can you explain what the effect of ignoring |
In response to your "Another possibility" comment: I tend to prefer solutions that don't require the caller to inspect the state of its collaborators. Instead, the callee should have a sensible interpretation for all possible sequences of messages (method calls) it receives, and its state should be encapsulated. The caller should just tell the driver what it wants, not ask the driver questions. See my recent tweets and my article on websocket-driver for some further explanation of this. |
Yeah, I agree that the "another possibility" solution isn't as good as the one I implemented here, which is why I sent in this one. The bug I'm seeing is, I have code that uses But let's say your code decides for whatever reason in some point between the constructor returning and the success of the TCP connection that it should |
If you decide to open a client connection but then close it before the TCP connection succeeds, the websocket-driver change tested by this commit will ensure that it will actually close, rather than ignoring the close() method. The change to API.close also seems correct to me, though I'm not sure if there are any observable changes if you don't do it.
driver.close() before driver.start() should close
If you call
close
on the driver before callingstart
, it's currently ignored. You might think this is just a matter of "don't use the API that way". But when it's being run from Faye WebSocket.Client, you don't really have a choice:start
is invoked automatically and asynchronously when the TCP connection succeeds, and you definitely might want to change your mind and close the socket sometime between construction and TCP success. I will create a PR for faye/faye-websocket-node as well adding a test (which depends on this PR).