Skip to content

Conversation

@ronag
Copy link
Member

@ronagronag commented Mar 8, 2020

If the socket is not detached then a future call to res.destroy
(through e.g. pipeline) would unecessarily kill the socket while
its in the agent free list.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@ronagronag added the http Issues or PRs related to the http subsystem. label Mar 8, 2020
@ronag
Copy link
MemberAuthor

ronag commented Mar 8, 2020

@szmarczak I think this is the fix you were looking for.

@ronagronag added the semver-major PRs that contain breaking changes and should be released in the next major version. label Mar 8, 2020
@ronag
Copy link
MemberAuthor

ronag commented Mar 8, 2020

I'm not sure whether setting socket to null here can cause more breakage... but it does make sense to set it to null. Also given the quote above IncomingMessage.destroy

// It's possible that the socket will be destroyed, and removed from // any messages, before ever calling this. In that case, just skip // it, since something else is destroying this connection anyway. 

@szmarczak
Copy link
Member

Looks amazing, you're a lifesaver!

If the socket is not detached then a future call to res.destroy (through e.g. pipeline) would unecessarily kill the socket while its in the agent free list.
@ronagronag changed the title stream: detach socket from IncomingMessage on keep-alivehttp: detach socket from IncomingMessage on keep-aliveMar 8, 2020
@ronagronagforce-pushed the http-client-res-destroy branch from 4ed671f to 30601b5CompareMarch 8, 2020 22:48
@addaleax
Copy link
Member

@nodejs-github-bot
Copy link
Collaborator

@BridgeARBridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 9, 2020
@ronag
Copy link
MemberAuthor

CITGM looks good

ronag added a commit that referenced this pull request Mar 10, 2020
If the socket is not detached then a future call to res.destroy (through e.g. pipeline) would unecessarily kill the socket while its in the agent free list. PR-URL: #32153 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]>
@ronag
Copy link
MemberAuthor

Landed in c1b2f6a

@ronagronag closed this Mar 10, 2020
@szmarczak
Copy link
Member

Since this isn't a breaking change, will this be backported?

@ronag
Copy link
MemberAuthor

@szmarczak it's labeled as semver-major, sorry :(

hyj1991 added a commit to hyj1991/urllib that referenced this pull request May 14, 2020
res.socket has been detached from IncomingMessage in node-v14.x Reference: nodejs/node#32153
hyj1991 added a commit to hyj1991/urllib that referenced this pull request May 14, 2020
res.socket has been detached from IncomingMessage in node-v14.x Reference: nodejs/node#32153
fengmk2 pushed a commit to node-modules/urllib that referenced this pull request May 15, 2020
res.socket has been detached from IncomingMessage in node-v14.x Reference: nodejs/node#32153
request1.socket.destroy();

response.socket.once('close',common.mustCall(()=>{
request1.socket.once('close',common.mustCall(()=>{
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it's no longer testing what it used to be testing (just working around the fact that response.socket is cleared now by attaching the event to an unrelated socket?). Proper fix would be to leave the event on response.socket and just attach it before the socket is cleared (up 3 lines, right after response.pipe)?

I'm not actually familiar with this code, just in here since this test started breaking on Node v14 over in http-parser-js, which has a fork of some of these tests, but I noticed the old code also had a big comment about how important the timing/ordering of attaching that event listener was.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.httpIssues or PRs related to the http subsystem.semver-majorPRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@ronag@szmarczak@addaleax@nodejs-github-bot@jasnell@Jimbly@BridgeAR