Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging without a network connection caused an exception #726

Closed
GerhardRi opened this issue Feb 5, 2015 · 15 comments
Closed

Debugging without a network connection caused an exception #726

GerhardRi opened this issue Feb 5, 2015 · 15 comments

Comments

@GerhardRi
Copy link

Without a network connection, no network adapters are installed, trying to debug caused an exception on my Win8.1 computer.

Steps to reproduce (io.js Versions 1.0.4 and 1.1.0):

C:\gg>iojs.exe debug test.js
    < Debugger listening on port 5858
    connecting to port 5858.............There was an internal error in Node's debugger. Please report this bug.
    getaddrinfo ENOENT localhost:5858
    Error: getaddrinfo ENOENT localhost:5858
        at Object.exports._errnoException (util.js:738:11)
        at errnoException (dns.js:30:15)
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:75:26)

After installing a Loopback Adapter it works fine:

    C:\gg>iojs.exe debug test.js
    < Debugger listening on port 5858
    connecting to port 5858... ok
    break in C:\gg\test.js:1
    > 1 console.log(process.config); 
@Fishrock123
Copy link
Contributor

@GerhardRi Can you post code that causes this without modules?

Otherwise, it is likely that the debugger you are using has native bindings and does not support io.js (yet). (See this list.)

@lidlanca
Copy link

lidlanca commented Feb 5, 2015

You can't use network stack without a network interface.

@GerhardRi
Copy link
Author

It's just a local programm no network connections at all
This ist my Code:

console.log(process.config);
console.log(process.versions);

I don't use an external debugger, just the build-in command line debugger

@lidlanca
Copy link

lidlanca commented Feb 5, 2015

When a program uses networking even for local communication it requires a network interface.

When you start the debugger it tried to bind to an interface, then wait for connections from the target.
which can be remote or local.

loopback interface is a virtual network interface that allow local programs communicate using a network stack.

@GerhardRi
Copy link
Author

As you can see ping the localhost and 127.0.0.1 works und doing the same with node.exe works too

C:\gg>iojs debug test.js
< Debugger listening on port 5858
connecting to port 5858.............There was an internal error in Node's debugger. Please report this bug.
getaddrinfo ENOENT localhost:5858
Error: getaddrinfo ENOENT localhost:5858
    at Object.exports._errnoException (util.js:738:11)
    at errnoException (dns.js:30:15)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:75:26)

C:\gg>node debug test.js
< debugger listening on port 5858
connecting... ok
break in C:\Users\Gerhard\Downloads\test.js:1
  1 console.log(process.config);
  2 console.log(process.versions);
  3
debug>
(^C again to quit)
debug>

C:\gg>ping localhost

Ping wird ausgeführt für Laptop [::1] mit 32 Bytes Daten:
Antwort von ::1: Zeit<1ms
Antwort von ::1: Zeit<1ms
Antwort von ::1: Zeit<1ms
Antwort von ::1: Zeit<1ms

Ping-Statistik für ::1:
    Pakete: Gesendet = 4, Empfangen = 4, Verloren = 0
    (0% Verlust),
Ca. Zeitangaben in Millisek.:
    Minimum = 0ms, Maximum = 0ms, Mittelwert = 0ms

C:\gg>ping 127.0.0.1

Ping wird ausgeführt für 127.0.0.1 mit 32 Bytes Daten:
Antwort von 127.0.0.1: Bytes=32 Zeit<1ms TTL=128
Antwort von 127.0.0.1: Bytes=32 Zeit<1ms TTL=128
Antwort von 127.0.0.1: Bytes=32 Zeit<1ms TTL=128

Ping-Statistik für 127.0.0.1:
    Pakete: Gesendet = 3, Empfangen = 3, Verloren = 0
    (0% Verlust),
Ca. Zeitangaben in Millisek.:
    Minimum = 0ms, Maximum = 0ms, Mittelwert = 0ms
STRG-C

@ofrobots
Copy link
Contributor

ofrobots commented Feb 6, 2015

I suspect that the problem might be related to the fact that 'node debug' starts two processes that communicate over port 5858. If there is no loopback network interface, then this might not work.

@lidlanca
Copy link

lidlanca commented Feb 6, 2015

ping.exe works, may be due to implementation exception when handling "localhost". When the tool recognize that the target is a localhost address it probably doesn't bother sending any icmp packets and assume success. (also see: "Martian packet")

I wouldn't consider the ping tool as a control element in the question.
ps if you ping from node as well it might still use ping.exe under the hood.

@bnoordhuis
Copy link
Member

I think we should be able to avoid the DNS resolve step by connecting to 127.0.0.1 instead of localhost. Does this patch help?

diff --git a/lib/_debugger.js b/lib/_debugger.js
index 955080f..7881d72 100644
--- a/lib/_debugger.js
+++ b/lib/_debugger.js
@@ -1620,7 +1620,7 @@ Interface.prototype.trySpawn = function(cb) {
   var self = this,
       breakpoints = this.breakpoints || [],
       port = exports.port,
-      host = 'localhost',
+      host = '127.0.0.1',
       childArgs = this.args;

   this.killChild();

(You'll have to recompile the binary after applying the patch. Or you could hex-edit the existing binary, the strings are equally long. :-))

@GerhardRi
Copy link
Author

It works with a patched exe, i replaced all the 'localhost' with '127.0.0.1'
Thank you all for your support

@cjihrig
Copy link
Contributor

cjihrig commented Feb 6, 2015

@bnoordhuis wouldn't that patch cause issues on machines that only support IPv6?

@bnoordhuis
Copy link
Member

@cjihrig It would. But what machine supports IPv6 but not IPv4? It seems like an academic issue to me.

@cjihrig
Copy link
Contributor

cjihrig commented Feb 6, 2015

I agree, but similar problems have come up before. nodejs/node-v0.x-archive#7637

@bnoordhuis
Copy link
Member

Right, I can see how only IPv6 might be externally routable. But disallowing IPv4 localhost traffic? Seems implausible, it would break a lot of existing programs.

@cjihrig
Copy link
Contributor

cjihrig commented Feb 6, 2015

Good point. This will never be an external connection. +1 from me then. If it does break for anyone, I'm sure they'll let us know.

bnoordhuis added a commit to bnoordhuis/io.js that referenced this issue Feb 6, 2015
On machines without network connectivity, a DNS lookup for 'localhost'
may fail.  Connect to 127.0.0.1 to skip the host resolve step.

Fixes: nodejs#726
PR-URL: nodejs#741
Reviewed-By: Colin Ihrig <[email protected]>
@bnoordhuis
Copy link
Member

Fixed in 9dc9ec3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants