Skip to content

Commit

Permalink
fix: catch errors when destroying invalid upgrades (#658)
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.
  • Loading branch information
jonathanneve authored and darrachequesne committed Nov 20, 2022
1 parent 99adb00 commit 425e833
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ export class Server extends BaseServer {
setTimeout(function() {
// @ts-ignore
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 425e833

Please sign in to comment.