Issue type
Brief description
I'm authoring a service that schedules websocket connections to a diverse set of workers. When there is an intermittent connection on one worker and the websocket connection needs to be relocated to another, I can't manage to dispose the instance with failure. It doesn't help to call the function close 'cause it fails to set the variable _isClosing to true since the connection isn't open yet. Also, after the next unsuccessful attempt, it sets the variable _isReconnecting to true so that the condition for reconnection always evaluates to true and continues forever.
Steps to reproduce
- Construct a WSv2 instance with
autoReconnect set to true
- Disable the network interface that provides the instance with internet connection
- Call the function
close on the WSv2 instance and see for yourself that it doesn't dispose the instance while continuing to register timeouts for reconnection
Additional Notes:
- For now, I'm making use of a workaround as follows to overcome this issue:
let disposed = false
ws.dispose = async () => {
if (!disposed) {
ws.on('auth', ws.dispose)
ws.on('error', ws.dispose)
ws.on('close', () => {ws._isClosing = true; ws._isReconnecting = false})
disposed = true
}
try {
await ws.close()
} catch {}
}
- With this in place, I can call the function
dispose and get rid of the instance completely
Issue type
Brief description
I'm authoring a service that schedules websocket connections to a diverse set of workers. When there is an intermittent connection on one worker and the websocket connection needs to be relocated to another, I can't manage to dispose the instance with failure. It doesn't help to call the function
close'cause it fails to set the variable_isClosingtotruesince the connection isn't open yet. Also, after the next unsuccessful attempt, it sets the variable_isReconnectingtotrueso that the condition for reconnection always evaluates to true and continues forever.Steps to reproduce
autoReconnectset totruecloseon the WSv2 instance and see for yourself that it doesn't dispose the instance while continuing to register timeouts for reconnectionAdditional Notes:
disposeand get rid of the instance completely