From c2b5ea218ca7ab11f0b0967b4037d9f109794096 Mon Sep 17 00:00:00 2001 From: Marcel Laverdet Date: Wed, 4 May 2011 06:51:15 +0900 Subject: [PATCH] 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. --- lib/_debugger.js | 57 +++++++++++++++++++++++++++++++----------------- src/node.cc | 2 +- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/lib/_debugger.js b/lib/_debugger.js index adde5004807..2714fc52dc8 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -1046,19 +1046,16 @@ Interface.prototype.trySpawn = function(cb) { this.pause(); - setTimeout(function() { - process.stdout.write('connecting...'); - var client = self.client = new Client(); - client.connect(exports.port); + var client = self.client = new Client(); + var connectionAttempts = 0; - client.once('ready', function() { - process.stdout.write('ok\r\n'); + client.once('ready', function() { + 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(); - }); + // 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() { @@ -1067,17 +1064,37 @@ Interface.prototype.trySpawn = function(cb) { self.killChild(); if (!self.quitting) self.term.prompt(); }); + }); - client.on('unhandledResponse', function(res) { - console.log('\r\nunhandled res:'); - console.log(res); - self.term.prompt(); - }); + client.on('unhandledResponse', function(res) { + console.log('\r\nunhandled res:'); + console.log(res); + self.term.prompt(); + }); - client.on('break', function(res) { - self.handleBreak(res.body); - }); - }, 100); + client.on('break', function(res) { + self.handleBreak(res.body); + }); + + 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); }; diff --git a/src/node.cc b/src/node.cc index fa64bb9902d..e76b0e217da 100644 --- a/src/node.cc +++ b/src/node.cc @@ -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); }