Browse Source

debugger: don't spawn child process in remote mode

When debug in remote mode with host:port or pid, the interface
spawn child process also. If the debugger agent is running, will
get following output:

```
< Error: listen EADDRINUSE :::5858
<     at Object.exports._errnoException (util.js:734:11)
<     at exports._exceptionWithHostPort (util.js:757:20)
<     at Agent.Server._listen2 (net.js:1155:14)
<     at listen (net.js:1181:10)
<     at Agent.Server.listen (net.js:1268:5)
<     at Object.start (_debug_agent.js:21:9)
<     at startup (node.js:68:9)
<     at node.js:799:3
```

This fix won't spawn child process and no more error message was
shown.

Reviewed-By: Julien Gilli <julien.gilli@joyent.com>
PR-URL: https://github.com/joyent/node/pull/14172
v0.12.3-release
Jackson Tian 10 years ago
committed by Julien Gilli
parent
commit
f0ef597e09
  1. 39
      lib/_debugger.js

39
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);
});
});
}
};

Loading…
Cancel
Save