Skip to content

Commit 0d00b06

Browse files
committed
[fix] destroy() websockets in case of an error
Not doing so caused websockets in `CLOSE_WAIT` to pile up and cause proxy to exceed open file descriptor limit.
1 parent 13c34d0 commit 0d00b06

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/node-http-proxy/http-proxy.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,17 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer)
611611
// connections.
612612
//
613613
function proxyError (err) {
614-
reverseProxy.end();
615-
if (self.emit('webSocketProxyError', req, socket, head)) {
616-
return;
617-
}
614+
reverseProxy.destroy();
615+
616+
process.nextTick(function () {
617+
//
618+
// Destroy the incoming socket in the next tick, in case the error handler
619+
// wants to write to it.
620+
//
621+
socket.destroy();
622+
});
618623

619-
socket.end();
624+
self.emit('webSocketProxyError', req, socket, head);
620625
}
621626

622627
//

0 commit comments

Comments
 (0)