Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
http: graceful shutdown on res.end()
On Windows and OSX, the HTTP server will often make
the OS send a TCP RST packet by shutting down the
socket before all incoming data has been read.
Normally, libuv should take care of this (?), but it does
not on Windows and OSX

Refs: #35904
  • Loading branch information
mmomtchev committed Nov 4, 2020
commit 07219ab2f544ae10417dbc6f377129bbbf39d704
5 changes: 4 additions & 1 deletion lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,10 @@ function resOnFinish(req, res, socket, state, server) {

if (res._last) {
if (typeof socket.destroySoon === 'function') {
socket.destroySoon();
if (socket.readableEnded)
socket.destroySoon();
else
socket.on('end', socket.destroySoon);
} else {
socket.end();
}
Expand Down
5 changes: 1 addition & 4 deletions test/parallel/test-https-truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ function httpsTest() {

server.listen(0, function() {
const opts = { port: this.address().port, rejectUnauthorized: false };
https.get(opts).on('response', function(res) {
https.get(opts).on('response', function (res) {
test(res);
}).on('error', () => {
// TODO: investigate why the server closes with a TCP RST on Windows
// https://github.com/nodejs/node/issues/35904
});
});
}
Expand Down