Skip to content

[x] http: added closed property - #28621

Closed
ronag wants to merge 1 commit into
nodejs:masterfrom
nxtedition:feat-http-closed
Closed

[x] http: added closed property#28621
ronag wants to merge 1 commit into
nodejs:masterfrom
nxtedition:feat-http-closed

Conversation

@ronag

@ronagronag commented Jul 10, 2019

Copy link
Copy Markdown
Member

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-botnodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Jul 10, 2019
@ronag
ronagforce-pushed the feat-http-closed branch 8 times, most recently from 847be88 to a554a24CompareJuly 10, 2019 11:40
Comment threaddoc/api/http.md Outdated
Comment threaddoc/api/http.md Outdated
Comment threaddoc/api/http.md Outdated
Comment threaddoc/api/http.md Outdated
@ronag
ronagforce-pushed the feat-http-closed branch 4 times, most recently from d5bb19f to 02b82d8CompareJuly 10, 2019 14:31
@ronagronag mentioned this pull request Jul 10, 2019
4 tasks
@ronag
ronagforce-pushed the feat-http-closed branch from 68eaf08 to 02b82d8CompareJuly 10, 2019 22:06
@BridgeAR

Copy link
Copy Markdown
Member

@nodejs/http PTAL

@ronag
ronagforce-pushed the feat-http-closed branch 2 times, most recently from 0321930 to 49ab8faCompareJuly 12, 2019 10:21
@ronag

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
Member

@nodejs/collaborators This could use some reviews.

@sebdeckerssebdeckers left a comment

Copy link
Copy Markdown
Contributor

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.

@benjamingrbenjamingr left a comment

Copy link
Copy Markdown
Member

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

ronag commented Jul 13, 2019

Copy link
Copy Markdown
MemberAuthor

@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

ronag commented Jul 13, 2019

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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

@benjamingrbenjamingr left a comment

Copy link
Copy Markdown
Member

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.

Comment threadlib/_http_server.js Outdated
@ronag
ronagforce-pushed the feat-http-closed branch 3 times, most recently from f8eeaee to 9bcc445CompareJuly 13, 2019 12:55
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

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.

Comment threadlib/_http_client.js Outdated
@ronag
ronagforce-pushed the feat-http-closed branch from 9bcc445 to 88e06a3CompareJuly 14, 2019 11:27
@ronag

ronag commented Jul 14, 2019

Copy link
Copy Markdown
MemberAuthor

@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
Copy Markdown
MemberAuthor

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

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

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.

Comment threadlib/_http_server.js Outdated
Comment threadlib/_http_server.js Outdated
Comment threadtest/parallel/test-http-connect-req-res.js Outdated
Comment threadtest/parallel/test-http-req-res-close.js Outdated
@ronag
ronagforce-pushed the feat-http-closed branch 2 times, most recently from 45eead6 to 2f5b684CompareJuly 16, 2019 08:38
@ronag

Copy link
Copy Markdown
MemberAuthor

@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
Copy Markdown
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
ronagforce-pushed the feat-http-closed branch from 2f5b684 to e4ea031CompareJuly 16, 2019 08:54
@ronag

ronag commented Jul 16, 2019

Copy link
Copy Markdown
MemberAuthor

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


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

Copy link
Copy Markdown
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.

@ronagronag mentioned this pull request Jul 23, 2019
4 tasks
@ronag

Copy link
Copy Markdown
MemberAuthor

Closing for now.

@ronagronag closed this Aug 26, 2019
@ronagronag changed the title http: added closed property[x] http: added closed propertyAug 26, 2019
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib / srcIssues 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

@ronag@BridgeAR@Trott@nodejs-github-bot@mcollina@sebdeckers@benjamingr@vsemozhetbyt