Skip to content
Closed
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
http: destroy clean incoming messages in one tick
When an incoming message is destroyed after being fully received with
no error, complete the destroy synchronously instead of deferring the
callback with process.nextTick(). The deferral only exists so that
'error' listeners attached right after destroy(err) still receive the
error, which cannot matter when there is no error. 'close' is still
emitted asynchronously by the stream machinery.

Reduces the per-request nextTick count of a hello-world HTTP server
from 6 to 5.

Signed-off-by: Matteo Collina <hello@matteocollina.com>
  • Loading branch information
mcollina committed Sep 2, 2026
commit 962c042103b2d60157db4e95fb3456bbd89513f6
7 changes: 7 additions & 0 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ IncomingMessage.prototype._destroy = function _destroy(err, cb) {
cleanup();
process.nextTick(onError, this, e || err, cb);
});
} else if (err == null && !this.aborted) {
// The message was received completely and is being destroyed cleanly:
// complete the destroy synchronously. 'close' is still emitted on a
// later tick by the stream machinery. The deferral below only exists
// so that 'error' listeners attached right after destroy(err) still
// receive the error, which cannot matter when there is no error.
cb();
} else {
process.nextTick(onError, this, err, cb);
}
Expand Down
Loading