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

In the WebSocketClientChannel example, ECONNREFUSED crashes the app #25

Open
vjpr opened this issue Feb 25, 2021 · 0 comments
Open

In the WebSocketClientChannel example, ECONNREFUSED crashes the app #25

vjpr opened this issue Feb 25, 2021 · 0 comments

Comments

@vjpr
Copy link

vjpr commented Feb 25, 2021

If it cannot connect to the server, the app will crash because there is no error event handler.

The error handler in the example is only attached after open.

    let ws: WebSocket | null = null
    try {
      ws = new WebSocket(this._host)
    } catch (err) {
      setTimeout(() => this._init, 500)
    }
    ws.on('error', (err) => { <------- added
      console.log({err})
    })
    ;(ws as WebSocket).on('open', () => {
      this._ws = ws as WebSocket
      this._ws.on('close', reinit)
      this._ws.on('error', e => {
        this._error(e)
        reinit()
      })
Error: connect ECONNREFUSED 127.0.0.1:55555
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1142:16)
Emitted 'error' event on WebSocket instance at:
    at ClientRequest.<anonymous> (/Uxxx/node_modules/.pnpm/[email protected]/node_modules/ws/lib/websocket.js:579:15)
    at ClientRequest.emit (events.js:315:20)
    at Socket.socketErrorListener (_http_client.js:463:9)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:100:8)
    at emitErrorCloseNT (internal/streams/destroy.js:68:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant