-
Notifications
You must be signed in to change notification settings - Fork 90
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] Create new IWebSocketFeed when reconnecting #117
Conversation
@zaccharles is correct. Since the "new WebSocketFeed" was removed from Start and created at the client. Dispose is not needed on close. The simplest solution is to remove the "dispose" from close. |
I just moved my production code to use this latest...it's a bit broken at the moment, hopefully this weekend it will be back up and able to test. |
@BradForsythe If you just remove the
|
I haven't looked into WebSocket4Net, but it looks like something isn't being closed properly or recreated when needed. I suppose it would be ideal if the WebSocket could be reused instead of recreated. That doesn't seem to be the case, so for now it's proably best to continue disposing it and making a new one. |
@zaccharles Yes. My project is back up. And I definitely get all kinds of weirdness when just removing dispose. I have an external implementation of Websocket4Net and it is possible to open and close without having to recreate. Looking into this a little later...time to eat! |
thanks @zaccharles! @BradForsythe let me know what you find before I merge this fix. |
@zaccharles Your method to create each time we open and close is workable. @dougdellolio I have been able to implement open and closing the socket without recreating. Kind of using your original approach but without disposing and recreating, and not using the IWebSocket interface. I am thinking recreating the resources is more time consuming, but maybe not a big deal. For me ... I have a need to stop and start the socket when I detect errors or my "mini L2 books" need to resync. This can be done with separate methods to unsubscribe and resubscribe and not have to start and stop sockets. Even better! To summarize: Either way, new methods would be good to unsubscribe and resubscribe. Still there are times throughout the day GDAX decided to close your connection, or for whatever reason the subscriptions are not all accepted. Opening and closing the socket cures this. In these cases speed is likely not an issue. Well, time to get something to eat for real now! |
going to merge this and release new version. thanks @BradForsythe and @zaccharles! |
This reverts commit 5c402c4.
This change is to fix a
NullReferenceException
which is thrown upon reconnecting.The reason this exception is thrown is that
WebSocket_Closed
disposes theWebSocket
(webSocketFeed
) here.WebSocket.Dispose
is setting it'sTcpClientSession
tonull
here. As a result, when we callStart
and try toOpen
the web socket again here, we get the exception due toClient
beingnull
.My change modifies our
WebSocket
class to take aFunc<IWebSocketFeed>
so that each time we callStart
, we can make a newIWebSocketFeed
. There is an open issue, kerryjiang/WebSocket4Net#99, about this preventing reuse. Other socket libraries suggest just creating a new client like this PR, which work for me in practice.It'd be nice if this could be merged, and if a new NuGet package could be published to pick up other changes (like the WebSocketX events that were added).
Thanks!