diff --git a/lib/_debugger.js b/lib/_debugger.js index c4155ce4c75384..6f7a80b77a822a 100644 --- a/lib/_debugger.js +++ b/lib/_debugger.js @@ -1627,6 +1627,7 @@ Interface.prototype.trySpawn = function(cb) { this.killChild(); assert(!this.child); + var isRemote = false; if (this.args.length === 2) { var match = this.args[1].match(/^([^:]+):(\d+)$/); @@ -1635,21 +1636,13 @@ Interface.prototype.trySpawn = function(cb) { // `node debug localhost:5858` host = match[1]; port = parseInt(match[2], 10); - this.child = { - kill: function() { - // TODO Do we really need to handle it? - } - }; + isRemote = true; } } else if (this.args.length === 3) { // `node debug -p pid` if (this.args[1] === '-p' && /^\d+$/.test(this.args[2])) { - this.child = { - kill: function() { - // TODO Do we really need to handle it? - } - }; process._debugProcess(parseInt(this.args[2], 10)); + isRemote = true; } else { var match = this.args[1].match(/^--port=(\d+)$/); if (match) { @@ -1661,10 +1654,13 @@ Interface.prototype.trySpawn = function(cb) { } } - this.child = spawn(process.execPath, childArgs); + if (!isRemote) { + // pipe stream into debugger + this.child = spawn(process.execPath, childArgs); - this.child.stdout.on('data', this.childPrint.bind(this)); - this.child.stderr.on('data', this.childPrint.bind(this)); + this.child.stdout.on('data', this.childPrint.bind(this)); + this.child.stderr.on('data', this.childPrint.bind(this)); + } this.pause(); @@ -1708,9 +1704,10 @@ Interface.prototype.trySpawn = function(cb) { client.on('error', connectError); function connectError() { - // If it's failed to connect 4 times then don't catch the next error + // If it's failed to connect 10 times then print failed message if (connectionAttempts >= 10) { - client.removeListener('error', connectError); + self.stdout.write(' failed, please retry\n'); + return; } setTimeout(attemptConnect, 500); } @@ -1721,10 +1718,12 @@ Interface.prototype.trySpawn = function(cb) { client.connect(port, host); } - this.child.stderr.once('data', function() { - setImmediate(function() { - self.print('connecting to port ' + port + '..', true); - attemptConnect(); + self.print('connecting to ' + host + ':' + port + ' ..', true); + if (isRemote) { + attemptConnect(); + } else { + this.child.stderr.once('data', function() { + setImmediate(attemptConnect); }); - }); + } };