Skip to content

Commit

Permalink
http: reuse socket only when it is drained
Browse files Browse the repository at this point in the history
Preserve 'prefinish' event
  • Loading branch information
ywave620 committed Jul 20, 2022
1 parent c81839b commit 8c9adbf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ ObjectSetPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
ObjectSetPrototypeOf(ClientRequest, OutgoingMessage);

ClientRequest.prototype._finish = function _finish() {
FunctionPrototypeCall(OutgoingMessage.prototype._finish, this);
if (hasObserver('http')) {
startPerf(this, kClientRequestStatistics, {
type: 'http',
Expand Down
12 changes: 7 additions & 5 deletions lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const {
} = primordials;

const { getDefaultHighWaterMark } = require('internal/streams/state');
const assert = require('internal/assert');
const EE = require('events');
const Stream = require('stream');
const internalUtil = require('internal/util');
Expand Down Expand Up @@ -984,11 +985,12 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
};


// Subclasses HttpClientRequest and HttpServerResponse should
// implement this function. This function is called once all user data
// are flushed to the socket. Note that it has a chance that the socket
// is not drained.
OutgoingMessage.prototype._finish = function() {};
// This function is called once all user data are flushed to the socket.
// Note that it has a chance that the socket is not drained.
OutgoingMessage.prototype._finish = function _finish() {
assert(this.socket);
this.emit('prefinish');
};


// This logic is probably a bit confusing. Let me explain a bit:
Expand Down
1 change: 1 addition & 0 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ ServerResponse.prototype._finish = function _finish() {
},
});
}
OutgoingMessage.prototype._finish.call(this);
};


Expand Down

0 comments on commit 8c9adbf

Please sign in to comment.