websocket-kit
websocket-kit copied to clipboard
Should be able to force close the WebSocket
Is your feature request related to a problem? Please describe.
The close
method waits for acknowledgement from the server. In some situations we already know the connection is closed (e.g. if the reachability state to the server has changed), and would rather just force a disconnected state immediately.
Describe the solution you'd like
Introduce forceClose
method to WebSocket
, that just terminates the channel.
Actually, I looked a bit further into this, and you're still forced to incur a 5 second penalty between closing the channel and onClose
being triggered. This is a shutdown timeout for TLS connections built into NIO
.
This is really frustrating, 5 seconds is an unacceptably long time for a WebSocket to be stranded in a closing
state for my use case. So for example, if you set pingInterval
to 1 second, you'll actually be waiting at least 6 seconds until onClose
is triggered and you can attempt a connection restart.
Perhaps an onClosing
future would be useful in responding to these situations?
On further thought, since it might difficult to provide a reliable onClosing
that covers all possible closing scenarios, perhaps we should just deliver a onPingTimeout
that covers just this specific use case.