-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
debugger: fix debugger blocked main thread #2151
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,28 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var debug = require('_debugger'); | ||
|
||
var fork = require('child_process').fork; | ||
|
||
var scriptToDebug = common.fixturesDir + '/debug-connect.js'; | ||
|
||
var nodeProcess; | ||
|
||
var failed = true; | ||
try { | ||
process._debugProcess(process.pid); | ||
failed = false; | ||
} finally { | ||
// At least TRY not to leave zombie procs if this fails. | ||
if (failed) | ||
process.kill(); | ||
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. Instead of this, please do try {
process._debugProcess(process.pid);
} catch(ex) {
assert.fail('Debugging should not fail');
} |
||
} | ||
console.log('>>> starting debugger session'); | ||
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. Please avoid printing anything to the console in the tests. |
||
|
||
nodeProcess = fork(scriptToDebug); | ||
nodeProcess.send({ pid: process.pid }); | ||
|
||
nodeProcess.on('message', function(m) { | ||
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. Use nodeProcess.on('message', common.mustCall(function(m) {
...
})); |
||
process._debugEnd(); | ||
process.exit(); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
var assert = require('assert'); | ||
var debug = require('_debugger'); | ||
var pid; | ||
|
||
setTimeout(function() { | ||
if (pid) process.kill(pid, 'SIGTERM'); | ||
throw new Error('timeout'); | ||
}, 5000).unref(); | ||
|
||
function connectToDebug() { | ||
var c = new debug.Client(); | ||
console.log('>>> connecting...'); | ||
c.connect(5858); | ||
c.on('break', function(brk) { | ||
c.reqContinue(function() {}); | ||
}); | ||
} | ||
|
||
process.on('message', function(m) { | ||
pid = m.pid; | ||
connectToDebug(); | ||
process.send({ exit: 'exit' }); | ||
}); |
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.
Use
const
wherever the values are assigned once and never reassigned.