nwjs / nw.js

Call all Node.js modules directly from DOM/WebWorker and enable a new way of writing applications with all Web technologies.
https://nwjs.io
MIT License
40.22k stars 3.88k forks source link

TypeError: isIP is not a function / Error: EFILE #5426

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi there,

we've encountered a problem with NW.js while using node's dgram module to establish a socket connection with specific network settings. We were able to reproduce this error on a Windows 7 machine with NW.js v0.18.1 and two network adapters (one is only virtual).

When binding a socket (udp4 or udp6) to a port, the following error can be catched:

TypeError: isIP is not a function
    at Object.lookup (dns.js:148:23)
    at lookup (dgram.js:27:14)
    at UDP.lookup4 [as lookup] (dgram.js:32:10)
    at Socket.bind (dgram.js:177:16)

I tried to reproduce this error with a simplified version of the code within a clean NW.js environment:

var dgram = require('dgram');
var socket = dgram.createSocket({
    type: 'udp4',
    reuseAddr: true
});
try {
    socket.bind(12345);
} catch (err) {
    console.log(err);
}

I got a different error message, but both seem to be related to the c-ares component in node's dns.js:

Error: EFILE
    at dns.js:5:23
    at NativeModule.compile (bootstrap_node.js:505:7)
    at NativeModule.require (bootstrap_node.js:446:18)
    at lookup (dgram.js:25:11)
    at UDP.lookup4 [as lookup] (dgram.js:32:10)
    at Socket.bind (dgram.js:177:16)

If both network adapters are active and connected, the code works fine. Deactivating the primary adapter and the IPv6 support of the second adapter produces the mentioned error. I also tried to activate both adapters and deactivate IPv6 support in both of them, but the code still worked.

Additionally I tried to execute the above example code directly with Node (v6.8.1 and v6.9.1) and it worked too, so it seems to be a problem in combination with NW.js.

rogerwang commented 7 years ago

It looks like cares library failed to get the DNS settings of your system when it initializes itself. I tried the code in my system with 2 adapters and cannot reproduce it. Could you please post DNS settings in your system?

ghost commented 7 years ago

Hi, checking the DNS settings was a good hint. The problem seems not to be related to the multi-adapter-environment, but to the set DNS-server. We were able to reproduce this behavior with one active adapter:

We also tried to manually set the DNS-server with a false entry (e.g. 127.0.0.1). The windows status page of the adapter showed no entry (correct, our localhost has no active DNS-server) but the error did not occur.