Skip to content

Fix socket read error when websocket upgrade failed#1439

Open
houfeng0923 wants to merge 1 commit intohttp-party:masterfrom
houfeng0923:master
Open

Fix socket read error when websocket upgrade failed#1439
houfeng0923 wants to merge 1 commit intohttp-party:masterfrom
houfeng0923:master

Conversation

@houfeng0923
Copy link
Copy Markdown

@houfeng0923 houfeng0923 commented May 8, 2020

WebSocket proxy will throw below exception when target server not ready(target nginx return default http 502 response at current time).


Proxying websocket to /rest/realtime
events.js:298
      throw er; // Unhandled 'error' event
      ^
Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:205:27)
Emitted 'error' event on TLSSocket instance at:
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at TLSSocket.onerror (_stream_readable.js:746:7)
    at TLSSocket.emit (events.js:321:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}

BTW, If cause by websocket, i think the reason for this is the same as the issue #1017

@houfeng0923
Copy link
Copy Markdown
Author

BTW, it only happen in ssl mode

pi0 added a commit to unjs/httpxy that referenced this pull request Mar 25, 2026
When a WebSocket upgrade request hits a target that responds with a
non-upgrade HTTP response (e.g., 502) and the upstream connection resets
mid-body, the `res` stream emits an unhandled error that crashes the
process. Add `res.on("error", onOutgoingError)` before piping, and guard
against writing to already-destroyed sockets.

Ref: http-party/node-http-proxy#1439
@pi0
Copy link
Copy Markdown

pi0 commented Mar 25, 2026

This issue has been fixed in unjs/httpxy#116.

pi0 added a commit to unjs/httpxy that referenced this pull request Mar 25, 2026
When a WebSocket upgrade request hits a target that responds with a
non-upgrade HTTP response (e.g., 502) and the upstream connection resets
mid-body, the `res` stream emits an unhandled error that crashes the
process. Add `res.on("error", onOutgoingError)` before piping, and guard
against writing to already-destroyed sockets.

Ref: http-party/node-http-proxy#1439
pi0 added a commit to unjs/httpxy that referenced this pull request Mar 25, 2026
When a WebSocket upgrade request hits a target that responds with a
non-upgrade HTTP response (e.g., 502) and the upstream connection resets
mid-body, the `res` stream emits an unhandled error that crashes the
process. Add `res.on("error", onOutgoingError)` before piping, and guard
against writing to already-destroyed sockets.

Ref: http-party/node-http-proxy#1439
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

Successfully merging this pull request may close these issues.

3 participants