在无法成功的 WebSocket 请求中发生崩溃

作者: jmattheis创建于 2020年7月15日更新于 2025年7月9日

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'); }) 在连接到不存在的路径后,服务器崩溃

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

错误:

events.js:291
      throw er; // Unhandled 'error' event
      ^
错误: 读取 ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:207:27)
在 Socket 实例上发出 'error' 事件:
    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'
}

内容来源: http-party/node-http-proxy