From 83c4071af871fc188298d7d591e95670bf9f9085 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Sun, 20 Nov 2022 02:23:53 +0100 Subject: [PATCH] fix: catch errors when destroying invalid upgrades Before this change, receiving an HTTP2 upgrade would make the server crash: > Error: read ECONNRESET > at TCP.onStreamRead (node:internal/stream_base_commons:217:20) { > errno: -104, > code: 'ECONNRESET', > syscall: 'read' > } This can be reproduced with Node.js v14.15.3, v16.18.1 and v18.12.1. Backported from https://github.com/socketio/engine.io/commit/425e833ab13373edf1dd5a0706f07100db14e3c6 --- lib/server.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/server.js b/lib/server.js index 4f2b8733..1ffce26b 100644 --- a/lib/server.js +++ b/lib/server.js @@ -487,6 +487,9 @@ Server.prototype.attach = function (server, options) { // then the socket needs to die! setTimeout(function () { if (socket.writable && socket.bytesWritten <= 0) { + socket.on('error', e => { + debug('error while destroying upgrade: %s', e.message); + }); return socket.end(); } }, destroyUpgradeTimeout);