Skip to content

Conversation

@luismfonseca
Copy link
Contributor

The underlying WebSocketClient connection will attempt to perform a WebSocket compliant graceful shutdown.

But in the case where a disconnect was called due to the client not receiving a pong, this will likely not succeed, which would delay the change to DISCONNECTED.

The underlying WebSocketClient connection will attempt to perform a WebSocket
compliant graceful shutdown.
But in the case where a disconnect was called due to the client not receiving
a pong, this will likely not succeed, which would delay the change to
DISCONNECTED.
@luismfonseca
Copy link
Contributor Author

/cc @jpatel531

@jpatel531
Copy link
Contributor

I'm happy to merge this - pinging @mdpye for a 2nd opinion

// Sometimes expected when we disconnected due to pong timeout
log.error("Received close from underlying socket when already disconnected. " + "Close code ["
+ code + "], Reason [" + reason + "], Remote [" + remote + "]");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a short circuit exit at the top would be much clearer than wrapping the entire effective body of the method in an if.

Also, we should not log at error level in expected circumstances.

@mdpye
Copy link
Contributor

mdpye commented Sep 1, 2016

The change as proposed skips the proper close procedure not just in the case of pong timeouts, but in all cases where the user elects to disconnect.

I can see why we might want an un-graceful shutdown in the pong timeout case, but we should restrict the hack to that case and respect the underlying state machine in the general case if you ask me.

We should at least remove ourselves as a listener from the outgoing underlyingConnection (it is replaced if you call connect() again in a DISCONNECTED state) when we move to DISCONNECTED, then the connection is guaranteed to be properly abandoned.

@luismfonseca
Copy link
Contributor Author

Ok, indeed it doesn't make sense to ungracefully shutdown connections that weren't timed out. I'll change this.

Not sure calling connect() when the intention is to clearly disconnect make sense. And I don't think it unregisters the listener.

I'd propose exposing the webSocketListener from WebSocketClientWrapper so it could be set to null.

@mdpye
Copy link
Contributor

mdpye commented Sep 1, 2016

Not sure calling connect() when the intention is to clearly disconnect make sense. And I don't think it unregisters the listener.

Yes, I wasn't proposing that we call connect(), just noting that once we have disconnected, we are done with that underlyingConnection, because it will be replaced if we do reconnect in future.

I'd propose exposing the webSocketListener from WebSocketClientWrapper so it could be set to null.

Cleanest would probably to be to create a removeListeners() method rather than actually exposing the listener property and setting it explicitly.

@luismfonseca
Copy link
Contributor Author

Made some improvements in 44701cd. I think I ruined the Wrapper abstraction a bit since I'm leaking it on the Factory.newWebSocketClientWrapper method...

@mdpye
Copy link
Contributor

mdpye commented Sep 2, 2016

Looks good.

I think I ruined the Wrapper abstraction a bit since I'm leaking it

Just add the removeListener method to the WebSocketClient interface...

@luismfonseca
Copy link
Contributor Author

Just add the removeListener method to the WebSocketClient interface...

Yes, but that's not directly under our control as we are using another library for that. I could make a PR to it though.

@mdpye
Copy link
Contributor

mdpye commented Sep 2, 2016

Ah, sorry, I didn't realise.

@luismfonseca
Copy link
Contributor Author

Actually, I'm not going to bother with a PR for the WebSocket client. Last two accepted there were in Feb 2016 and another in mid-August 2015. And the Feb one was this.

@luismfonseca luismfonseca merged commit c203254 into master Sep 5, 2016
@luismfonseca luismfonseca deleted the fix-pong-timeout-disconnect branch September 5, 2016 08:28
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

Successfully merging this pull request may close these issues.

4 participants