-
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
reused http parser can be associated to incorrect domain #25456
Comments
Reused parsers can be attached to the domain that corresponds to the active domain when the underlying socket was created, which is not necessarily correct. Instead, we attach parsers to the active domain if there is one when they're reused from the pool. Refs: #25456 PR-URL: #25459 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Node.js v8.x has reached the end-of-life and won't receive any fixes anymore. I am closing this since this issue seems to only apply to Node.js v8.x. If it does in fact also apply to newer versions, please leave a comment so that this can be reopened (@misterdjules I only saw a fix specifically for v8.x?). No matter if you run into this issue or not, please update to a newer Node.js version in case you still use v8.x. |
Reused parsers can be attached to the domain that corresponds to the active domain when the underlying socket was created, which is not necessarily correct. Instead, we attach parsers to the active domain if there is one when they're reused from the pool. Refs: nodejs/node#25456
The following program exits with an exit code of 1 when run with node built from the tip of the
v8.x
branch:What this programs above does is:
Creating one outgoing http request to a local http server, (let's call it request 1), in the context of a newly created domain (let's call it domain 1). This request uses an agent that has
keepAlive
set totrue
. The purpose of using an agent and settingkeepAlive
totrue
is to force the second request (see below) to reuse the same HTTP parser instance as this one.When request 1 completes, a second request is created using the same http agent but in the context of a separate domain (let's call it domain 2). In the response's
'end'
event listener of that request, an uncaught error is thrown.What we expect is that the domain in which the second request was created (domain 2) would handle that uncaught exception, but what happens is that instead the first domain handles it.
I think that the cause of this problem is that, when a HTTP parser is being reused from the pool, it's not re-attached to the active domain.
There is code in
parserOnIncomingClient
that seems to be responsible for attaching the parser to the correct domain, but it does so only if that parser wasn't already attached to a previous domain. That doesn't work when a parser is reused.I think the following patch would fix this issue in a way that is more robust:
This problem doesn't surface in node 10 because when a parser is reused, its underlying async resource is reinitialized and the proper async hooks events are emitted, which allows the domains state machine to associate the parser to the active domain.
The text was updated successfully, but these errors were encountered: