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
fixup: isServerRequest
  • Loading branch information
ronag committed Jul 10, 2021
commit ad257e56cb36c140b7b536eec44e3461140a3234
2 changes: 0 additions & 2 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const {
prepareError,
} = require('_http_common');
const { OutgoingMessage } = require('_http_outgoing');
const { kDestroy } = require('internal/streams/destroy');
const Agent = require('_http_agent');
const { Buffer } = require('buffer');
const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
Expand Down Expand Up @@ -610,7 +609,6 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
req.res = res;
res.req = req;
res[kDestroy] = null;

// Add our listener first, so that we guarantee socket cleanup
res.on('end', responseOnEnd);
Expand Down
6 changes: 0 additions & 6 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const {
} = primordials;

const { Readable, finished } = require('stream');
const { kDestroy } = require('internal/streams/destroy');

const kHeaders = Symbol('kHeaders');
const kHeadersCount = Symbol('kHeadersCount');
Expand Down Expand Up @@ -199,11 +198,6 @@ IncomingMessage.prototype._destroy = function _destroy(err, cb) {
}
};

IncomingMessage.prototype[kDestroy] = function(err) {
this.socket = null;
this.destroy(err);
};

IncomingMessage.prototype._addHeaderLines = _addHeaderLines;
function _addHeaderLines(headers, n) {
if (headers && headers.length) {
Expand Down
7 changes: 4 additions & 3 deletions lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
kDestroyed,
isDestroyed,
isFinished,
isServerRequest
} = require('internal/streams/utils');

const kDestroy = Symbol('kDestroy');
Expand Down Expand Up @@ -389,8 +390,9 @@ function destroyer(stream, err) {
}

// TODO: Remove isRequest branches.
if (typeof stream[kDestroy] === 'function') {
stream[kDestroy](err);
if (isServerRequest(stream)) {
stream.socket = null;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to prevent the socket from destroying in this case? Is there any chance to move this logic into IncomingMessage.prototype._destroy to decouple destroy logic a bit?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that the response is not destroyed. No it’s not possible to decouple to due breaking reasons. Unfortunately this is the only way.

stream.destroy(err);
} else if (isRequest(stream)) {
stream.abort();
} else if (isRequest(stream.req)) {
Expand All @@ -412,7 +414,6 @@ function destroyer(stream, err) {
}

module.exports = {
kDestroy,
construct,
destroyer,
destroy,
Expand Down
10 changes: 10 additions & 0 deletions lib/internal/streams/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ function isServerResponse(stream) {
);
}

function isServerRequest(stream) {
return (
typeof stream._consuming === 'boolean' &&
typeof stream._dumped === 'boolean' &&
stream.req?.upgradeOrConnect === undefined
);
}

function willEmitClose(stream) {
if (!isStream(stream)) return null;

Expand Down Expand Up @@ -194,5 +202,7 @@ module.exports = {
isWritableStream,
isWritableEnded,
isWritableFinished,
Comment thread
ronag marked this conversation as resolved.
isServerRequest,
isServerResponse,
willEmitClose,
};