Nodejs _debugger stalls between reqContinue and on('break') #9319
Description
There is an unusual stall between reqContinue and on('break') in node's debugger.
NOTE: this only occurs on node version 0.10.31 or above.
For example, given a program that is in a busy loop (with a break point inside the loop), I don't expect any delay between when I call continue and when my program hit the next break point. However, given such a program, when my program is paused (i.e. on break), if I wait x seconds to call continue, then it will take my program x seconds to hit the break point.
I'll clarify with a reduced case below:
Given the program below. All it does is busy loop.
var nodedebug = require('child_process').fork(__dirname + '/client.js', [process.pid, 5858]);
process.on('exit', function() {
nodedebug.kill('SIGTERM');
});
// wait for debugger to attach
setInterval(function() {
console.log('.'); // this is line 8
}, 100);
Now I write a client. This client will attach to the above busy loop program. Then, every n seconds, it will call continue, and measure how long it takes for the program to hit the next break point.
var repl = require('repl');
var baseDebugger = require('_debugger');
var client = new baseDebugger.Client();
var iteration = function () {
timeout = Math.floor(Math.random() * 10) * 1000; // random timeout between 0-9s
var time;
client.once('break', function() {
console.log("BREAK. waited " + (new Date().getTime() - time)/1000 + 's')
iteration();
});
setTimeout(function() {
client.reqContinue(function() {
console.log("REQCONTINUE after " + timeout/1000 +'s')
time = new Date().getTime()
});
}, timeout)
};
client.once('ready', function() {
client.setBreakpoint({
type: 'scriptRegExp',
target: '.*infiniteloop\.js',
line: 8
}, function() {
setTimeout(function(){
iteration();
}, 500)
});
});
process._debugProcess(process.argv[2]);
var host = 'localhost';
var port = 5858;
setTimeout(function(){
// wait 1s for debugger port to open
client.connect(port, host);
}, 1000)
I would expect such program to break almost immediately every time, but this is not the case:
Here's a sample output:
$ node ./infiniteloop.js
Hit SIGUSR1 - starting debugger agent.
debugger listening on port 5858
REQCONTINUE after 3s
.
BREAK. waited 0.007s // this is normal
REQCONTINUE after 2s
.
BREAK. waited 2.117s // waited 2s before breaking
REQCONTINUE after 5s
.
BREAK. waited 5.109s // waited 5s before breaking
REQCONTINUE after 5s
.
BREAK. waited 5.109s // waited 5s before breaking
REQCONTINUE after 9s
.
BREAK. waited 9.115s // waited 9s before breaking
This is the output in node version 0.10.30 and earlier, and is the output that I'm expecting:
$ node infiniteloop.js
Hit SIGUSR1 - starting debugger agent.
debugger listening on port 5858
REQCONTINUE after 2s
.
BREAK. waited 0.007s // no latency
REQCONTINUE after 8s
.
BREAK. waited 0.103s // no latency
REQCONTINUE after 8s
.
BREAK. waited 0.1s // no latency
REQCONTINUE after 2s
.
BREAK. waited 0.101s // no latency
REQCONTINUE after 4s
.
BREAK. waited 0.102s // no latency