Skip to content

Commit

Permalink
fix: catch errors when destroying invalid upgrades
Browse files Browse the repository at this point in the history
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 425e833
  • Loading branch information
darrachequesne committed Nov 20, 2022
1 parent f62f265 commit 83c4071
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 83c4071

Please sign in to comment.