-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: compat avoid bind and properly cleanup stream #20374
Conversation
ebc8bb2
to
34ad49a
Compare
d57ba33
to
6c86160
Compare
lib/internal/http2/compat.js
Outdated
} | ||
|
||
function onStreamTrailersReady() { | ||
this[kStream].sendTrailers(this[kTrailers]); | ||
const stream = this; | ||
const res = stream[kResponse]; |
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.
Why these extra variables instead of just:
this.sendTrailers(this[kResponse][kTrailers]);
?
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.
No particular reason. Just style. I'm fine with changing if you want me to?
6c86160
to
8a5874a
Compare
lib/internal/http2/compat.js
Outdated
} | ||
|
||
function onStreamTrailersReady() { | ||
this[kStream].sendTrailers(this[kTrailers]); | ||
stream.sendTrailers(this[kResponse][kTrailers]); |
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.
stream
should be this
8a5874a
to
96b0de9
Compare
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 is on a good track but needs a bit of cleanup.
lib/internal/http2/compat.js
Outdated
@@ -223,6 +222,31 @@ const proxySocketHandler = { | |||
} | |||
}; | |||
|
|||
function onRequestFinish() { |
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.
onStreamCloseRequest
? It's not really onRequestFinish
.
lib/internal/http2/compat.js
Outdated
@@ -223,6 +222,31 @@ const proxySocketHandler = { | |||
} | |||
}; | |||
|
|||
function onRequestFinish() { | |||
const stream = this; |
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.
Please don't reassign this
.
lib/internal/http2/compat.js
Outdated
|
||
stream[kProxySocket] = null; | ||
stream[kRequest] = undefined; | ||
stream.off('data', onStreamData); |
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.
Are all these detachments necessary? It will certainly make performance worse.
lib/internal/http2/compat.js
Outdated
} | ||
|
||
function onResponseFinish() { | ||
const stream = this; |
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.
Same as above: more accurate name and don't re-assign this
please.
lib/internal/http2/compat.js
Outdated
|
||
stream[kProxySocket] = null; | ||
stream[kResponse] = undefined; | ||
stream.off('drain', onStreamDrain); |
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.
Same as above. Unless this is 100% necessary, it would be better not to.
lib/internal/http2/compat.js
Outdated
@@ -382,13 +414,14 @@ class Http2ServerResponse extends Stream { | |||
this[kHeaders] = Object.create(null); | |||
this[kTrailers] = Object.create(null); | |||
this[kStream] = stream; | |||
this.writable = true; |
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 change doesn't seem to relate to this PR.
lib/internal/http2/compat.js
Outdated
@@ -236,6 +260,9 @@ class Http2ServerRequest extends Readable { | |||
this[kRawTrailers] = []; | |||
this[kStream] = stream; | |||
this[kAborted] = false; | |||
this.on('pause', onRequestPause); | |||
this.on('resume', onRequestResume); |
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 change doesn't seem to relate to this PR.
d7a0fbd
to
525429a
Compare
@apapirovski cleaned up |
20d1dce
to
93c4f7d
Compare
lib/internal/http2/compat.js
Outdated
const res = this[kResponse]; | ||
const state = res[kState]; | ||
|
||
if (!this[kResponse] || this.headRequest !== state.headRequest) |
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.
res === undefined
would be cleaner check here.
lib/internal/http2/compat.js
Outdated
const req = this[kRequest]; | ||
const state = req[kState]; | ||
|
||
if (!this[kRequest]) |
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.
req === undefined
is more precise. Also please move const state =
after the check.
93c4f7d
to
823bc93
Compare
823bc93
to
ae50653
Compare
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 thanks!
ping @nodejs/http2 would be nice to have at least one more review on this. |
Can you add a test for this? |
FWIW I don't think it's possible to test this without exporting the |
👍 to exporting in the internal module. |
CI: https://ci.nodejs.org/job/node-test-pull-request/14865/ I will land this once done and create a test myself in a separate PR. |
PR-URL: #20374 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Landed in 0d762af |
PR-URL: #20374 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
PR-URL: nodejs#20374 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
PR-URL: nodejs#20374 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
PR-URL: nodejs#20374 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
PR-URL: nodejs#20374 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Avoid unnecessary function
bind
.Also fixes a bug where
kProxySocket
was assignednull
on the wrong object as well as properly cleanup the stream object.Checklis
make -j4 test
(UNIX), orvcbuild test
(Windows) passes