-
Notifications
You must be signed in to change notification settings - Fork 30k
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
http2: invoke connect callback immediately if session was connected #19842
Conversation
http2.connect
callback immediately if the Http2Session
was connected synchronously
Is it possible to add a test? |
@pietermees as @lpinca pointed out, it would be great if you could add a test. There is a documentation for how to write tests in |
@pietermees and thanks a lot for contributing! Great that you went ahead to fix the issue right away 🎉. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some changes that need to be made before this lands. A test should definitely be added as it would help the suggested changes below, plus any other potential issues.
lib/internal/http2/core.js
Outdated
if (session.connecting) | ||
session.once('connect', listener); | ||
else | ||
listener.call(this, socket); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The context passed to the listener
should be session
rather than this
from the current scope. Also, please use Reflect.apply(listener, session, [socket]);
for user-provided callbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed in 1fee57b30601f351c5b8eb60d2797917c0604a6b
In d575ac7a49ca38f84fcd20f4ef0a01786e3e0f23 I added documentation for the |
And I'll add a test :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just the comment about the version.
doc/api/http2.md
Outdated
@@ -320,6 +320,17 @@ added: v9.4.0 | |||
Will be `true` if this `Http2Session` instance has been closed, otherwise | |||
`false`. | |||
|
|||
#### http2session.connecting | |||
<!-- YAML | |||
added: v9.12.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be a fixed value. Instead of v9.12.0
just put in: REPLACEME
. This is going to be automatically be replaced during publishing a new release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 8316d4f36b769fdf3224b65fdd32f4194a441ada
doc/api/http2.md
Outdated
added: v9.12.0 | ||
--> | ||
|
||
* Value: {boolean} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a hint: the Value
will probably be removed soon. See #19869. If that lands before this PR, this should get a update and vice versa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: it just landed and now the Value
should be removed ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this is a new section, so no conflicts for now, but the * Value: {boolean}
should b replaced with just * {boolean}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 8316d4f36b769fdf3224b65fdd32f4194a441ada
lib/internal/http2/core.js
Outdated
if (session.connecting) | ||
session.once('connect', listener); | ||
else | ||
Reflect.apply(listener, session, [socket]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jasnell @mcollina Thinking about this a bit more, should we use process.nextTick
and emit a connect
event regardless rather than directly calling the listener
? I know we don't recommend this code pattern anywhere but something like the following would still not work after this change:
const session = http2.connect(SERVER_URL, { createConnection: () => socket });
session.once('connect', listener);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@apapirovski I think we should copy-paste what we are doing for http, https, net and tls. So, we should adhere to the prevailing pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm good with emitting on nextTick
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually do emit connect
though on the following lines:
node/lib/internal/http2/core.js
Line 777 in e37effe
this.emit('connect', this, socket); node/lib/internal/http2/core.js
Line 819 in e37effe
this.emit('connect', this, socket);
So I guess we're saying that we'll register the listener
as a connect
listener and change the two emit
s to run on the next tick?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See f21670f5d51d451cd2f2203f14d0f804ba107905
6998ae8
to
27171ce
Compare
@BridgeAR @apapirovski @jasnell updated to emit connect on next tick and added a test |
27171ce
to
e9f09bd
Compare
streamlined the commits |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@mcollina the CI error seems to be that |
That's probably flaky. We can land this. For the flaky test, open an issue with the output of the failure if you can :). |
No need to open a new issue. See #19903 |
@cjihrig sure that's the same issue? The tests seem to succeed, but the process keeps running:
See https://ci.nodejs.org/job/node-test-commit-linux/17820/nodes=debian8-x86/console |
@apapirovski are you ok for this to land? |
@cjihrig Yup, exactly. I’m sorry for the inconvenience, I think this was worth it though… |
Thanks for making the changes @pietermees — sorry for the back-and-forth. I think this should be ready to land. |
Landed in 4ac7753...2852521 |
PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
PR-URL: nodejs#19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
PR-URL: nodejs#19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
Backport-PR-URL: #20456 PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
Backport-PR-URL: #20456 PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
Backport-PR-URL: #20456 PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
Backport-PR-URL: #20456 PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
Backport-PR-URL: #20456 PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
Backport-PR-URL: #20456 PR-URL: #19842 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
This seems to till be an issue in Node 12. I have it working on 10 and 14, but it doesn't work for me in 12. I'm digging through Node.js code to see what could potentially cause 12 to really break when 10 and 14 works, and I find weird things, undocumented. What is this (on master): Lines 1570 to 1571 in 2e6c3e2
These two options, |
Never mind, this is fixed by #33343 |
Resolves #19839
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes