Skip to content
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

Failing to close a websocket connection when autoReconnect is set to true #577

Open
barhun opened this issue Jan 15, 2022 · 0 comments
Open

Comments

@barhun
Copy link

barhun commented Jan 15, 2022

Issue type

  • bug

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
@barhun barhun changed the title Fails to close a websocket connection with autoReconnect set to true Failing to close a websocket connection when autoReconnect set to true May 31, 2022
@barhun barhun changed the title Failing to close a websocket connection when autoReconnect set to true Failing to close a websocket connection when autoReconnect is set to true May 31, 2022
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

No branches or pull requests

1 participant