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

[x] http: added closed property #28621

Closed
wants to merge 1 commit into from

Conversation

ronag
Copy link
Member

@ronag ronag commented Jul 10, 2019

This is an alternative to finished and onFinished.isFinished to more accurately indicate when a request/response has completed.

With this PR the frequently used on-finished npm package should no longer be necessary as the "same" (assumed) functionality can be achieved using the 'close' event and closed property.

Refs: #28412

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

@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jul 10, 2019
@ronag ronag force-pushed the feat-http-closed branch 8 times, most recently from 847be88 to a554a24 Compare July 10, 2019 11:40
doc/api/http.md Outdated Show resolved Hide resolved
doc/api/http.md Outdated Show resolved Hide resolved
doc/api/http.md Outdated Show resolved Hide resolved
doc/api/http.md Outdated Show resolved Hide resolved
@ronag ronag force-pushed the feat-http-closed branch 4 times, most recently from d5bb19f to 02b82d8 Compare July 10, 2019 14:31
@ronag ronag mentioned this pull request Jul 10, 2019
4 tasks
@BridgeAR
Copy link
Member

@nodejs/http PTAL

@ronag ronag force-pushed the feat-http-closed branch 2 times, most recently from 0321930 to 49ab8fa Compare July 12, 2019 10:21
@ronag
Copy link
Member Author

ronag commented Jul 12, 2019

I've got a lot of other pending fixes and PR's that depend on this. Would be nice to get it merged before I start "spamming" with new PR's.

@Trott
Copy link
Member

Trott commented Jul 13, 2019

@nodejs/collaborators This could use some reviews.

Copy link
Contributor

@sebdeckers sebdeckers left a comment

Choose a reason for hiding this comment

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

Nice, LGTM. Would be great if there were docs and a test for the added http2 compat properties.

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

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

The code changes look good but I am just not sure we should do this. It adds another property and I am really not sure why we need it vs. just listening to an event. An extra variable for every single http request for something I don't understand isn't something I'm comfortable approving. Can you motivate this?

@ronag
Copy link
Member Author

ronag commented Jul 13, 2019

@benjamingr Because currently, there is no way to check whether an http object is closed or not. If you are using a framework such as koa or similar it might already be too late to register a 'close' listener by the time you get access to the object. Also adding a close listener on every http request has a more significant performance overhead.

In summary there are cases already out in the wild which cannot solve this and are incorrectly depending on msg.finished or onFinished.isFinished non of which properly implement it.

@ronag
Copy link
Member Author

ronag commented Jul 13, 2019

Also I have other pending fixes that depend on this, e.g.

  • Every call after 'close' should be a noop. Currently we have that logic which depends on finished which is not enough.
  • a complete getter which fully replaces finished in terms of checking if any further useful work can be done.

@ronag
Copy link
Member Author

ronag commented Jul 13, 2019

If you are worried about size we can also do things like: nxtedition@7355716

Copy link
Member

@benjamingr benjamingr left a comment

Choose a reason for hiding this comment

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

I still think .closed should be done on the framework side but the argument regarding other fixes this would enable (in particular doing work on a closed request) are a compelling enough argument to me.

@ronag ronag force-pushed the feat-http-closed branch 3 times, most recently from f8eeaee to 9bcc445 Compare July 13, 2019 12:55
@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

I'm not convinced of this change. I would rather prefer that we switch IncomingMessage to use the the emitClose and autoDestroy option instead, making it less of a snowflake in the stream world. I'm not sure if that is actually doable.

lib/_http_client.js Outdated Show resolved Hide resolved
@ronag
Copy link
Member Author

ronag commented Jul 14, 2019

@mcollina would it make more sense to rename closed to destroyed and that way it pretends to follows the streams spec. Later we can put extra work into removing this "hack" and use autoDestroy? i.e. from the outside it would be the "same" but the implementation detail is suboptimal.

@ronag
Copy link
Member Author

ronag commented Jul 14, 2019

@mcollina I tried the autoClose & autoDestroy. But it seems a bit too complicated for me...

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

I don't see tests or docs for http2.

lib/_http_server.js Outdated Show resolved Hide resolved
lib/_http_server.js Outdated Show resolved Hide resolved
test/parallel/test-http-connect-req-res.js Show resolved Hide resolved
test/parallel/test-http-req-res-close.js Show resolved Hide resolved
@ronag ronag force-pushed the feat-http-closed branch 2 times, most recently from 45eead6 to 2f5b684 Compare July 16, 2019 08:38
@ronag
Copy link
Member Author

ronag commented Jul 16, 2019

@mcollina you asked me to add more checks to https://github.com/nodejs/node/blob/master/test/parallel/test-http-connect-req-res.js.

Those checks will actually fail since e.g. req.'close' is emitted before `socket.'end'. But that bug is not related to this PR per se and is something I suggest we solve separately and regardless if this PR lands or not.

@mcollina
Copy link
Member

Those checks will actually fail since e.g. req.'close' is emitted before `socket.'end'. But that bug is not related to this PR per se and is something I suggest we solve separately and regardless if this PR lands or not.

Please add tests that verifies the current behavior, having it unspecified is going to cause more issues. Add a comment on it that explain your thinking. I would also open a separate issue about it.

@ronag
Copy link
Member Author

ronag commented Jul 16, 2019

@mcollina: Done, if you agree, I will add a separate PR with test that are "correct" and fail.

@@ -446,6 +450,10 @@ class Http2ServerResponse extends Stream {
stream.on('timeout', onStreamTimeout(kResponse));
}

get closed() {
return this[kState].closed;
}
Copy link
Member

Choose a reason for hiding this comment

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

No tests have been added for these.

@ronag ronag mentioned this pull request Jul 23, 2019
4 tasks
@ronag
Copy link
Member Author

ronag commented Aug 26, 2019

Closing for now.

@ronag ronag closed this Aug 26, 2019
@ronag ronag changed the title http: added closed property [x] http: added closed property Aug 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants