Skip to content

Commit c2b5ea2

Browse files
laverdetry
authored andcommitted
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.
1 parent 5ab3ea3 commit c2b5ea2

2 files changed

Lines changed: 38 additions & 21 deletions

File tree

lib/_debugger.js

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,19 +1046,16 @@ Interface.prototype.trySpawn = function(cb) {
10461046

10471047
this.pause();
10481048

1049-
setTimeout(function() {
1050-
process.stdout.write('connecting...');
1051-
var client = self.client = new Client();
1052-
client.connect(exports.port);
1049+
var client = self.client = new Client();
1050+
var connectionAttempts = 0;
10531051

1054-
client.once('ready', function() {
1055-
process.stdout.write('ok\r\n');
1052+
client.once('ready', function() {
1053+
process.stdout.write(' ok\r\n');
10561054

1057-
// since we did debug-brk, we're hitting a break point immediately
1058-
// continue before anything else.
1059-
client.reqContinue(function() {
1060-
if (cb) cb();
1061-
});
1055+
// since we did debug-brk, we're hitting a break point immediately
1056+
// continue before anything else.
1057+
client.reqContinue(function() {
1058+
if (cb) cb();
10621059
});
10631060

10641061
client.on('close', function() {
@@ -1067,17 +1064,37 @@ Interface.prototype.trySpawn = function(cb) {
10671064
self.killChild();
10681065
if (!self.quitting) self.term.prompt();
10691066
});
1067+
});
10701068

1071-
client.on('unhandledResponse', function(res) {
1072-
console.log('\r\nunhandled res:');
1073-
console.log(res);
1074-
self.term.prompt();
1075-
});
1069+
client.on('unhandledResponse', function(res) {
1070+
console.log('\r\nunhandled res:');
1071+
console.log(res);
1072+
self.term.prompt();
1073+
});
10761074

1077-
client.on('break', function(res) {
1078-
self.handleBreak(res.body);
1079-
});
1080-
}, 100);
1075+
client.on('break', function(res) {
1076+
self.handleBreak(res.body);
1077+
});
1078+
1079+
client.on('error', connectError);
1080+
function connectError() {
1081+
// If it's failed to connect 4 times then don't catch the next error
1082+
if (connectionAttempts >= 4) {
1083+
client.removeListener('error', connectError);
1084+
}
1085+
setTimeout(attemptConnect, 50);
1086+
}
1087+
1088+
function attemptConnect() {
1089+
++connectionAttempts;
1090+
process.stdout.write('.');
1091+
client.connect(exports.port);
1092+
}
1093+
1094+
setTimeout(function() {
1095+
process.stdout.write('connecting..');
1096+
attemptConnect();
1097+
}, 50);
10811098
};
10821099

10831100

src/node.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ static void EnableDebug(bool wait_connect) {
22222222
assert(r);
22232223

22242224
// Print out some information.
2225-
fprintf(stderr, "debugger listening on port %d\r\n", debug_port);
2225+
fprintf(stderr, "debugger listening on port %d", debug_port);
22262226
}
22272227

22282228

0 commit comments

Comments
 (0)