10000 Fix websocket socket close before response · http-party/node-http-proxy@bcb1930 · GitHub
[go: up one dir, main page]

Skip to content

Commit bcb1930

Browse files
Fix websocket socket close before response
There are situations where the socket can already be closed. Writing to it will result in a "This socket has been ended by the other party" error which results in the node service to terminate (cannot be catched by a try-catch block).
1 parent 9b96cd7 commit bcb1930

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/http-proxy/passes/ws-incoming.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ module.exports = {
111111
proxyReq.on('error', onOutgoingError);
112112
proxyReq.on('response', function (res) {
113113
// if upgrade event isn't going to happen, close the socket
114-
if (!res.upgrade) {
114+
if (!res.upgrade && socket.readyState !== "closed") {
115115
socket.write(createHttpHeader('HTTP/' + res.httpVersion + ' ' + res.statusCode + ' ' + res.statusMessage, res.headers));
116116
res.pipe(socket);
117117
}

0 commit comments

Comments
 (0)
0