-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Fixed cluster inspect port logic #13619
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| 'use strict'; | ||
|
|
||
| const common = require('../common'); | ||
|
|
||
| common.skipIfInspectorDisabled(); | ||
|
|
||
| const assert = require('assert'); | ||
| const cluster = require('cluster'); | ||
|
|
||
| const debuggerPort = common.PORT; | ||
| const childProcess = require('child_process'); | ||
|
|
||
| let offset = 0; | ||
|
|
||
| /* | ||
| * This test suite checks that inspector port in cluster is incremented | ||
| * for different execArgv combinations | ||
| */ | ||
|
|
||
| function testRunnerMain() { | ||
| spawnMaster({ | ||
| execArgv: ['--inspect'], | ||
| workers: [{expectedPort: 9230}] | ||
| }); | ||
|
|
||
| let port = debuggerPort + offset++ * 10; | ||
|
|
||
| spawnMaster({ | ||
| execArgv: [`--inspect=${port}`], | ||
| workers: [ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you describe the issue, please? I'm not quite getting what's going wrong..
Port collisions between tests within single test run?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes. Probably will not be a problem if you use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is relevant to sequential tests too?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, unfortunatly
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what I suggested doing https://github.com/nodejs/node/pull/13373/files#diff-4b2a51d5cbf4c8edb50bfd0f7016bb84R16 And just close the workers immediately.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've looked at the test again and I don't think my case is relevant to yours. Testing zero port + offset will be always dangerous because you can get port near some-constantly-occupied port. That case couldn't take place with |
||
| {expectedPort: port + 1}, | ||
| {expectedPort: port + 2}, | ||
| {expectedPort: port + 3} | ||
| ] | ||
| }); | ||
|
|
||
| port = debuggerPort + offset++ * 10; | ||
|
|
||
| spawnMaster({ | ||
| execArgv: ['--inspect', `--inspect-port=${port}`], | ||
| workers: [{expectedPort: port + 1}] | ||
| }); | ||
|
|
||
| port = debuggerPort + offset++ * 10; | ||
|
|
||
| spawnMaster({ | ||
| execArgv: ['--inspect', `--debug-port=${port}`], | ||
| workers: [{expectedPort: port + 1}] | ||
| }); | ||
|
|
||
| port = debuggerPort + offset++ * 10; | ||
|
|
||
| spawnMaster({ | ||
| execArgv: [`--inspect=0.0.0.0:${port}`], | ||
| workers: [{expectedPort: port + 1, expectedHost: '0.0.0.0'}] | ||
| }); | ||
|
|
||
| port = debuggerPort + offset++ * 10; | ||
|
|
||
| spawnMaster({ | ||
| execArgv: [`--inspect=127.0.0.1:${port}`], | ||
| workers: [{expectedPort: port + 1, expectedHost: '127.0.0.1'}] | ||
| }); | ||
|
|
||
| if (common.hasIPv6) { | ||
| port = debuggerPort + offset++ * 10; | ||
|
|
||
| spawnMaster({ | ||
| execArgv: [`--inspect=[::]:${port}`], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this work? (before #13478 lands)?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That depends on your definition of work :) Yes, worker listens on ipv4 address, but that's not what I'm checking here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| workers: [{expectedPort: port + 1, expectedHost: '::'}] | ||
| }); | ||
|
|
||
| port = debuggerPort + offset++ * 10; | ||
|
|
||
| spawnMaster({ | ||
| execArgv: [`--inspect=[::1]:${port}`], | ||
| workers: [{expectedPort: port + 1, expectedHost: '::1'}] | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| function masterProcessMain() { | ||
| const workers = JSON.parse(process.env.workers); | ||
|
|
||
| for (const worker of workers) { | ||
| cluster.fork({ | ||
| expectedPort: worker.expectedPort, | ||
| expectedHost: worker.expectedHost | ||
| }).on('exit', common.mustCall(checkExitCode)); | ||
| } | ||
| } | ||
|
|
||
| function workerProcessMain() { | ||
| const {expectedPort, expectedHost} = process.env; | ||
|
|
||
| assert.strictEqual(process.debugPort, +expectedPort); | ||
|
|
||
| if (expectedHost !== 'undefined') { | ||
| assert.strictEqual( | ||
| process.binding('config').debugOptions.host, | ||
| expectedHost | ||
| ); | ||
| } | ||
|
|
||
| process.exit(); | ||
| } | ||
|
|
||
| function spawnMaster({execArgv, workers}) { | ||
| childProcess.fork(__filename, { | ||
| env: { | ||
| workers: JSON.stringify(workers), | ||
| testProcess: true | ||
| }, | ||
| execArgv | ||
| }).on('exit', common.mustCall(checkExitCode)); | ||
| } | ||
|
|
||
| function checkExitCode(code, signal) { | ||
| assert.strictEqual(code, 0); | ||
| assert.strictEqual(signal, null); | ||
| } | ||
|
|
||
| if (!process.env.testProcess) { | ||
| testRunnerMain(); | ||
| } else if (cluster.isMaster) { | ||
| masterProcessMain(); | ||
| } else { | ||
| workerProcessMain(); | ||
| } | ||
This file was deleted.
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 not put this just in
src/node_config.cc?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.
For consistency sake? I was looking at
config_preserve_symlinksas an exampleThere 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 where I'd put it. I can see how it has wider scope than the two files that will use it, but putting it in a header guarantees consistency between the place of definition and place of use.
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.
Ack.