Skip to content

Commit f0ef597

Browse files
JacksonTianJulien Gilli
authored and
Julien Gilli
committed
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 <[email protected]> PR-URL: nodejs/node-v0.x-archive#14172
1 parent c63a39b commit f0ef597

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

lib/_debugger.js

+19-20
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,7 @@ Interface.prototype.trySpawn = function(cb) {
16271627
this.killChild();
16281628
assert(!this.child);
16291629

1630+
var isRemote = false;
16301631
if (this.args.length === 2) {
16311632
var match = this.args[1].match(/^([^:]+):(\d+)$/);
16321633

@@ -1635,21 +1636,13 @@ Interface.prototype.trySpawn = function(cb) {
16351636
// `node debug localhost:5858`
16361637
host = match[1];
16371638
port = parseInt(match[2], 10);
1638-
this.child = {
1639-
kill: function() {
1640-
// TODO Do we really need to handle it?
1641-
}
1642-
};
1639+
isRemote = true;
16431640
}
16441641
} else if (this.args.length === 3) {
16451642
// `node debug -p pid`
16461643
if (this.args[1] === '-p' && /^\d+$/.test(this.args[2])) {
1647-
this.child = {
1648-
kill: function() {
1649-
// TODO Do we really need to handle it?
1650-
}
1651-
};
16521644
process._debugProcess(parseInt(this.args[2], 10));
1645+
isRemote = true;
16531646
} else {
16541647
var match = this.args[1].match(/^--port=(\d+)$/);
16551648
if (match) {
@@ -1661,10 +1654,13 @@ Interface.prototype.trySpawn = function(cb) {
16611654
}
16621655
}
16631656

1664-
this.child = spawn(process.execPath, childArgs);
1657+
if (!isRemote) {
1658+
// pipe stream into debugger
1659+
this.child = spawn(process.execPath, childArgs);
16651660

1666-
this.child.stdout.on('data', this.childPrint.bind(this));
1667-
this.child.stderr.on('data', this.childPrint.bind(this));
1661+
this.child.stdout.on('data', this.childPrint.bind(this));
1662+
this.child.stderr.on('data', this.childPrint.bind(this));
1663+
}
16681664

16691665
this.pause();
16701666

@@ -1708,9 +1704,10 @@ Interface.prototype.trySpawn = function(cb) {
17081704

17091705
client.on('error', connectError);
17101706
function connectError() {
1711-
// If it's failed to connect 4 times then don't catch the next error
1707+
// If it's failed to connect 10 times then print failed message
17121708
if (connectionAttempts >= 10) {
1713-
client.removeListener('error', connectError);
1709+
self.stdout.write(' failed, please retry\n');
1710+
return;
17141711
}
17151712
setTimeout(attemptConnect, 500);
17161713
}
@@ -1721,10 +1718,12 @@ Interface.prototype.trySpawn = function(cb) {
17211718
client.connect(port, host);
17221719
}
17231720

1724-
this.child.stderr.once('data', function() {
1725-
setImmediate(function() {
1726-
self.print('connecting to port ' + port + '..', true);
1727-
attemptConnect();
1721+
self.print('connecting to ' + host + ':' + port + ' ..', true);
1722+
if (isRemote) {
1723+
attemptConnect();
1724+
} else {
1725+
this.child.stderr.once('data', function() {
1726+
setImmediate(attemptConnect);
17281727
});
1729-
});
1728+
}
17301729
};

0 commit comments

Comments
 (0)