Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: http client response should always emit close when finished #17397

Closed
wants to merge 1 commit into from
Closed

http: http client response should always emit close when finished #17397

wants to merge 1 commit into from

Conversation

ronag
Copy link
Member

@ronag ronag commented Nov 30, 2017

fixes #17352

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

http

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Nov 30, 2017
@maclover7
Copy link
Contributor

@ronag Would you be able to look at the test coverage for this code and make sure it properly covers this behavior, or else would you be able to add new tests?

@addaleax
Copy link
Member

@nodejs/http

CI: https://ci.nodejs.org/job/node-test-commit/14482/

@ronag
Copy link
Member Author

ronag commented Nov 30, 2017

@maclover7: Sorry, not sure how to build a test for this case. The tests are still a bit over my head.

@BridgeAR
Copy link
Member

@nodejs/http @nodejs/testing anyone to provide some quick help?

// Socket closed before we emitted 'end' below.
res.emit('aborted');
res.on('end', function() {
res.emit('close');
Copy link
Member

Choose a reason for hiding this comment

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

Since you're here: this.emit('close') - saves a closure over res.

res.emit('close');
});
res.push(null);
} else {
res.emit('close');
Copy link
Member

Choose a reason for hiding this comment

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

Since res.readable == false, does that mean an 'end' event has already been emitted?

Copy link
Member Author

Choose a reason for hiding this comment

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

end will never be called if not readable at this point.

@BridgeAR
Copy link
Member

BridgeAR commented Feb 6, 2018

@ronag about writing a test:

The tests here work the same as if you would write code for your own project. So what you want to do is to write some code that would actually fail without this change. I guess you should know how to get there as you found out that it does not always emit a close when finishing.

The only difference here is that you have to include the "common" part as first require statement as done in every test file in the test folder. You probably want to add a new file in the "parallel" part.

In addition to that you have some extra helper functions that you find in the common part and that also has a individual documentation. But you should probably not need that at all.

To run the tests you first have to build the node executable (I guess you use a unix system, so run make -j4. On Windows it is something with the bat file ;-) ).
When that is done (it could take a while when doing it for the first time...) you can run the tests by running make -j4 test or to only your test file: python ./tools/test.py parallel/test-http-YOUR_FILE_NAME.js.

I hope that helps? :-)

@apapirovski
Copy link
Member

In addition to @BridgeAR's excellent guide, you could also take inspiration from the test here https://github.com/nodejs/node/blob/master/test/parallel/test-http-client-close-event.js and create a new one that hits the code path that you've modified.

@BridgeAR
Copy link
Member

@ronag would you mind taking another look? :-)

@ronag
Copy link
Member Author

ronag commented Feb 17, 2018

Sorry guys... I’m swamped... feel free to take over

@BridgeAR
Copy link
Member

@ronag too bad. And as a note: we are not all guys.

@apapirovski @jasnell would either of you be willing to write a test for this?

@jasnell
Copy link
Member

jasnell commented Feb 17, 2018

@ronag ... This isn't the place for that debate.

@BridgeAR
Copy link
Member

BridgeAR commented Mar 2, 2018

@nodejs/http @nodejs/http2 would someone be so kind and write a small test case for this?

@trivikr
Copy link
Member

trivikr commented Mar 2, 2018

@BridgeAR I can give it a try.
I need to post a new PR with changes shared by @ronag in this PR and add unit tests right?

@BridgeAR
Copy link
Member

BridgeAR commented Mar 2, 2018

@trivikr thanks a lot! :-) And yes, in this case I recommend to cherry-pick this commit and then add your changes and open a new PR for it.

@trivikr trivikr self-assigned this Mar 26, 2018
@BridgeAR
Copy link
Member

@trivikr do you still want to follow up on this? :-)

@trivikr
Copy link
Member

trivikr commented Apr 10, 2018

@BridgeAR The code is lying in my private branch since last month, let me add the tests and post a PR :-)

@trivikr
Copy link
Member

trivikr commented Apr 15, 2018

Closing this in favor of new PR #20043

@trivikr trivikr closed this Apr 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http.ClientRequest response object only emits close after abort?
9 participants