Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upchild_process: allow 'http_parser' monkey patching again #24006
Conversation
nodejs-github-bot
added
the
child_process
label
Oct 31, 2018
Jimbly
referenced this pull request
Oct 31, 2018
Closed
No longer able to monkey-patch HTTP parser #23716
This comment has been minimized.
This comment has been minimized.
|
@nodejs/child_process This could use some reviews. |
This comment has been minimized.
This comment has been minimized.
|
If this fix is acceptable, and, additionally, something the Node team wants to support going forward, I'll add a test case ensuring http_parser is not required prior to user-level code being run, however I totally understand if that's not something the project wants to be held to in the future. Regardless, since this is a small fix, it would be great to get this merged to Node v10 to fix issues users of http-parser-js are running into. |
This comment has been minimized.
This comment has been minimized.
joyeecheung
approved these changes
Nov 4, 2018
|
Regardless of the monkey-patchablility, it makes sense to lazy load the HTTP parser in child_process, so LGTM |
jasnell
approved these changes
Nov 4, 2018
cjihrig
approved these changes
Nov 4, 2018
Yes, please add a test. |
Jimbly
added a commit
to Jimbly/node
that referenced
this pull request
Nov 5, 2018
Jimbly
force-pushed the
Jimbly:patch-2
branch
from
cc2745c
to
db33bc5
Nov 5, 2018
Jimbly
added a commit
to Jimbly/node
that referenced
this pull request
Nov 5, 2018
Jimbly
force-pushed the
Jimbly:patch-2
branch
from
db33bc5
to
9984257
Nov 5, 2018
Jimbly
added a commit
to Jimbly/node
that referenced
this pull request
Nov 5, 2018
Jimbly
force-pushed the
Jimbly:patch-2
branch
from
9984257
to
05bf434
Nov 5, 2018
Jimbly
added a commit
to Jimbly/node
that referenced
this pull request
Nov 5, 2018
This comment has been minimized.
This comment has been minimized.
|
@cjihrig I've added a test (which fails on Node v10.1.0+, passes with this fix). |
cjihrig
approved these changes
Nov 5, 2018
|
Thanks, LGTM with a couple optional comments. |
| // Test in a child process with IPC (specific case of https://github.com/nodejs/node/issues/23716) | ||
| const child = fork(__filename, [ 'child' ]); | ||
| child.on('exit', common.mustCall((code, signal) => { | ||
| assert.strictEqual(code, 0); |
This comment has been minimized.
This comment has been minimized.
|
|
||
| // Test in our process | ||
| doTest(); | ||
| // Test in a child process with IPC (specific case of https://github.com/nodejs/node/issues/23716) |
This comment has been minimized.
This comment has been minimized.
cjihrig
Nov 5, 2018
Contributor
You could execute this block of code only if process.argv[2] !== 'child', then you could get rid of the logic above, only calling doTest() once, unconditionally. Then, since it's only called once, you could get rid of doTest(), and inline its body
This comment has been minimized.
This comment has been minimized.
Jimbly
Nov 5, 2018
Author
Contributor
Yeah, my first pass had the child process sending a message back to say things succeeded, so it was more complicated, and after I submitted my last change I did notice this could be simplified. Will do, since I'm making the other changes =).
cjihrig
reviewed
Nov 5, 2018
| } | ||
| } | ||
| DummyParser.REQUEST = Symbol(); | ||
| process.binding('http_parser').HTTPParser = DummyParser; |
This comment has been minimized.
This comment has been minimized.
cjihrig
Nov 5, 2018
Contributor
Oh, and I think this should be using internalBinding, since we recently moved toward gradually deprecating all of process.binding().
This comment has been minimized.
This comment has been minimized.
Jimbly
Nov 5, 2018
Author
Contributor
I saw that and tried internalBinding, but it complained with ReferenceError: internalBinding is not defined. Do you need to do something special to access this in tests and/or user-level code? I saw that 'http_parser' was on the 'process.binding white list' at some point, but I'm not sure if that's so that users can still get at it, or just a migration path toward deprecation.
This comment has been minimized.
This comment has been minimized.
cjihrig
Nov 5, 2018
Contributor
Yes, put this at the top of the file:
// Flags: --expose-internals
That lets you specify command line arguments that the test needs.
Then:
const { internalBinding } = require('internal/test/binding');
This comment has been minimized.
This comment has been minimized.
Jimbly
Nov 5, 2018
Author
Contributor
Okay, that seems to work for the test. I'm assuming the best option is still using process.binding('http_parser') for users of monkey patching in http-parser-js, or is there any non-test way to get at internalBinding?
Thanks for the comments and assistance, I'm a complete novice at the Node testing framework ^_^. I've updated the test and will ping when it's cleared Travis CI and ready for final review / merge.
Jimbly
force-pushed the
Jimbly:patch-2
branch
from
05bf434
to
abe4f50
Nov 5, 2018
Jimbly
added a commit
to Jimbly/node
that referenced
this pull request
Nov 5, 2018
This comment has been minimized.
This comment has been minimized.
|
Updated test case code after comments from @cjihrig. I think is is now ready to go! |
This comment has been minimized.
This comment has been minimized.
Trott
added
the
author ready
label
Nov 6, 2018
This comment has been minimized.
This comment has been minimized.
|
Looks like the test fails when run in a worker? 19:28:01 not ok 906 parallel/test-http-parser-lazy-loaded
19:28:01 ---
19:28:01 duration_ms: 0.515
19:28:01 severity: fail
19:28:01 exitcode: 1
19:28:01 stack: |-
19:28:01 (node:14125) internal/test/binding: These APIs are exposed only for testing and are not tracked by any versioning system or deprecation process.
19:28:01 internal/modules/cjs/loader.js:605
19:28:01 throw err;
19:28:01 ^
19:28:01
19:28:01 Error: Cannot find module 'internal/test/binding'
19:28:01 at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
19:28:01 at Function.Module._load (internal/modules/cjs/loader.js:529:25)
19:28:01 at Module.require (internal/modules/cjs/loader.js:658:17)
19:28:01 at require (internal/modules/cjs/helpers.js:22:18)
19:28:01 at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-custom-suites-freestyle/test/parallel/test-http-parser-lazy-loaded.js:5:29)
19:28:01 at Module._compile (internal/modules/cjs/loader.js:722:30)
19:28:01 at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
19:28:01 at Module.load (internal/modules/cjs/loader.js:620:32)
19:28:01 at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
19:28:01 at Function.Module._load (internal/modules/cjs/loader.js:552:3)
19:28:01
19:28:01 events.js:167
19:28:01 throw er; // Unhandled 'error' event
19:28:01 ^
19:28:01 AssertionError [ERR_ASSERTION]: Expected values to be strictly equal:
19:28:01
19:28:01 1 !== 0
19:28:01
19:28:01 at ChildProcess.child.on.common.mustCall (/home/iojs/build/workspace/node-test-commit-custom-suites-freestyle/test/parallel/test-http-parser-lazy-loaded.js:30:12)
19:28:01 at ChildProcess.<anonymous> (/home/iojs/build/workspace/node-test-commit-custom-suites-freestyle/test/common/index.js:340:15)
19:28:01 at ChildProcess.emit (events.js:182:13)
19:28:01 at Process.ChildProcess._handle.onexit (internal/child_process.js:254:12)
19:28:01 Emitted 'error' event at:
19:28:01 at Worker.[kOnErrorMessage] (internal/worker.js:332:10)
19:28:01 at Worker.[kOnMessage] (internal/worker.js:342:37)
19:28:01 at MessagePort.Worker.(anonymous function).on (internal/worker.js:279:57)
19:28:01 at MessagePort.emit (events.js:182:13)
19:28:01 at MessagePort.onmessage (internal/worker.js:84:8)
19:28:01 ...Maybe someone in @nodejs/workers knows the right way to fix? |
This comment has been minimized.
This comment has been minimized.
|
Does the the fork() call need |
This comment has been minimized.
This comment has been minimized.
I think you can run |
Jimbly
force-pushed the
Jimbly:patch-2
branch
from
abe4f50
to
eb4cd15
Nov 6, 2018
Jimbly
added a commit
to Jimbly/node
that referenced
this pull request
Nov 6, 2018
This comment has been minimized.
This comment has been minimized.
|
Looks like it reproduced with running |
tadhgcreedon
pushed a commit
to tadhgcreedon/node
that referenced
this pull request
Nov 11, 2018
BridgeAR
added a commit
that referenced
this pull request
Nov 14, 2018
kiyomizumia
added a commit
to kiyomizumia/node
that referenced
this pull request
Nov 15, 2018
This was referenced Nov 15, 2018
This comment has been minimized.
This comment has been minimized.
paulrutter
commented
Nov 18, 2018
|
Do these messages mean it won't end up in 10.x? |
Trott
added
the
lts-watch-v10.x
label
Nov 19, 2018
This comment has been minimized.
This comment has been minimized.
No, there just hasn't been a 10.x release proposed in the last couple weeks. I've added the |
This comment has been minimized.
This comment has been minimized.
|
I'm don't have a good recent record for label usage but this seems appropriate to me |
Jimbly commentedOct 31, 2018
•
edited
Lazy load _http_common and HTTPParser so that the 'http_parser' binding
can be monkey patched before any internal modules require it. This also
probably improves startup performance minimally for programs that never
require the HTTP stack.
Fixes: #23716
Fixes: creationix/http-parser-js#57
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes