From 5ae96908696b7a017df3efb48ec1f8c8be5c24b8 Mon Sep 17 00:00:00 2001 From: Daniele Belardi Date: Wed, 9 Dec 2020 13:31:02 +0100 Subject: [PATCH] http: add comments in _http_incoming PR-URL: https://github.com/nodejs/node/pull/33035 Refs: https://github.com/nodejs/node/issues/30625 Reviewed-By: Robert Nagy Reviewed-By: Matteo Collina Reviewed-By: Rich Trott --- lib/_http_incoming.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 1b6099a89dc65c..5442bfe7bb2479 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -171,6 +171,9 @@ IncomingMessage.prototype._destroy = function _destroy(err, cb) { // If aborted and the underlying socket not already destroyed, // destroy it. + // We have to check if the socket is already destroyed because finished + // does not call the callback when this methdod is invoked from `_http_client` + // in `test/parallel/test-http-client-spurious-aborted.js` if (this.socket && !this.socket.destroyed && this.aborted) { this.socket.destroy(err); const cleanup = finished(this.socket, (e) => { @@ -359,6 +362,9 @@ IncomingMessage.prototype._dump = function _dump() { }; function onError(instance, cb, error) { + // This is to keep backward compatible behavior. + // An error is emitted only if there are listeners attached to + // the event. if (instance.listenerCount('error') > 0) { cb(error); } else {