Skip to content

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/_debug_agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ exports.start = function start() {
});

agent.close();
agent.clients.forEach(function(client) {
client.destroy();
});
};

// Not used now, but anyway
Expand Down
28 changes: 28 additions & 0 deletions test/debugger/test-debugger-stop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';
var common = require('../common');
Copy link
Contributor

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.

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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this, please do assert.fail. In face, I would recommend doing

try {
  process._debugProcess(process.pid);
} catch(ex) {
  assert.fail('Debugging should not fail');
}

}
console.log('>>> starting debugger session');
Copy link
Contributor

Choose a reason for hiding this comment

The 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use common.mustCall, like this

nodeProcess.on('message', common.mustCall(function(m) {
...
}));

process._debugEnd();
process.exit();
});
25 changes: 25 additions & 0 deletions test/fixtures/debug-connect.js
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' });
});