Attempt to connect to debug process more than once

The debugger would give up after only 100ms but on my system this
timeout isn't enough. The startup process is now modified to try 6
times every 50ms instead.

Fixes #1010.
This commit is contained in:
Marcel Laverdet 2011-05-04 06:51:15 +09:00 committed by Ryan Dahl
parent 5ab3ea3955
commit c2b5ea218c
2 changed files with 38 additions and 21 deletions

View File

@ -1046,20 +1046,17 @@ Interface.prototype.trySpawn = function(cb) {
this.pause();
setTimeout(function() {
process.stdout.write('connecting...');
var client = self.client = new Client();
client.connect(exports.port);
var connectionAttempts = 0;
client.once('ready', function() {
process.stdout.write('ok\r\n');
process.stdout.write(' ok\r\n');
// since we did debug-brk, we're hitting a break point immediately
// continue before anything else.
client.reqContinue(function() {
if (cb) cb();
});
});
client.on('close', function() {
console.log('\nprogram terminated');
@ -1067,6 +1064,7 @@ Interface.prototype.trySpawn = function(cb) {
self.killChild();
if (!self.quitting) self.term.prompt();
});
});
client.on('unhandledResponse', function(res) {
console.log('\r\nunhandled res:');
@ -1077,7 +1075,26 @@ Interface.prototype.trySpawn = function(cb) {
client.on('break', function(res) {
self.handleBreak(res.body);
});
}, 100);
client.on('error', connectError);
function connectError() {
// If it's failed to connect 4 times then don't catch the next error
if (connectionAttempts >= 4) {
client.removeListener('error', connectError);
}
setTimeout(attemptConnect, 50);
}
function attemptConnect() {
++connectionAttempts;
process.stdout.write('.');
client.connect(exports.port);
}
setTimeout(function() {
process.stdout.write('connecting..');
attemptConnect();
}, 50);
};

View File

@ -2222,7 +2222,7 @@ static void EnableDebug(bool wait_connect) {
assert(r);
// Print out some information.
fprintf(stderr, "debugger listening on port %d\r\n", debug_port);
fprintf(stderr, "debugger listening on port %d", debug_port);
}