forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inspector: added --inspect-publish-uid-ipc-path argument
The argument takes the IPC path as an argument when it is passed, the inspector web socket server will send its full web socket url to IPC server with the given path at the start. This flag is required to solve inspector web socket url discovery the problem for child processes. Only one discovery option is available right now; it is searching for ws:// URLs in stderr of node process. This approach does not work when the parent process ignores the stderr of the child process, e.g. update-notifier uses this technique. Discussion about using files instead can be found here: nodejs/diagnostics#298
- Loading branch information
1 parent
282e2f6
commit a1c4fe7
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
|
||
common.skipIfInspectorDisabled(); | ||
|
||
const assert = require('assert'); | ||
const { spawn } = require('child_process'); | ||
const net = require('net'); | ||
|
||
(async function test() { | ||
await testWithServer(); | ||
await testWithoutServer(); | ||
})(); | ||
|
||
|
||
async function testWithServer() { | ||
const pipe = common.PIPE; | ||
const CHILD_COUNT = 5; | ||
const sockets = []; | ||
const server = net.createServer((socket) => { | ||
let buf = ''; | ||
socket.on('data', (d) => buf += d.toString()); | ||
socket.on('end', () => sockets.push(...buf.split(' '))); | ||
}).listen(pipe); | ||
await runNodeWithChildren(CHILD_COUNT, pipe); | ||
server.close(); | ||
assert.strictEqual(CHILD_COUNT + 1, sockets.length); | ||
sockets.forEach((socket) => { | ||
const m = socket.match(/ws:\/\/[^/]+\/[-a-z0-9]+/); | ||
assert.strictEqual(m[0], socket); | ||
}); | ||
} | ||
|
||
async function testWithoutServer() { | ||
await runNodeWithChildren(5, common.PIPE); | ||
} | ||
|
||
function runNodeWithChildren(childCount, pipe) { | ||
const nodeProcess = spawn(process.execPath, [ | ||
'--inspect=0', | ||
`--inspect-publish-uid-ipc-path=${pipe}`, | ||
'-e', `(${main.toString()})()` | ||
], { | ||
env: { | ||
COUNT: childCount | ||
} | ||
}); | ||
return new Promise((resolve) => nodeProcess.on('close', resolve)); | ||
|
||
function main() { | ||
const { spawn } = require('child_process'); | ||
if (process.env.COUNT * 1 === 0) | ||
return; | ||
spawn(process.execPath, process.execArgv, { | ||
env: { | ||
COUNT: process.env.COUNT - 1 | ||
} | ||
}); | ||
} | ||
} |