Crash on unsuccessful websocket request

Author: jmattheisCreated Jul 15, 2020Updated Jul 9, 2025
const x = require('http-proxy');
const srv = x.createServer({ target: 'http://echo.websocket.org', ws: true, changeOrigin: true }).listen(5555);
srv.on('error', () => {
    console.log('err');
})

After connecting to a path that doesn't exist, the server crashes

$ wscat -c 'ws://localhost:5555/a'

Error:

events.js:291
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:207:27)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (internal/streams/destroy.js:100:8)
    at emitErrorCloseNT (internal/streams/destroy.js:68:3)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read'
}

Source: http-party/node-http-proxy