WSL icon indicating copy to clipboard operation
WSL copied to clipboard

The networkInterfaces function in the "os" API of node.js does not work under "bash on windows"

Open choclaudio opened this issue 10 years ago • 15 comments

  • A brief description With the lastest version of node.js installed (currently 4.5) the os.networkInterfaces method throws an exception: invalid argument, uv_interface_addresses
  • Your Windows build number 14393

choclaudio avatar Aug 23 '16 17:08 choclaudio

Thanks for reporting the issue. Could you please share out a strace of the failure so we can see if there is a system call failure?

stehufntdev avatar Aug 23 '16 18:08 stehufntdev

Very likely same reason /sbin/ifconfig fails

ericblade avatar Aug 23 '16 18:08 ericblade

Thanks @choclaudio for reporting this! It sounds to me like a duplicate of #468; in particular, this comment notes the same error text that you have identified.

There's a bunch of discussion on that ticket, including a workaround posted by @therealkenc here. You could try that workaround to see if it helps you out.

aseering avatar Aug 23 '16 22:08 aseering

Hi everyone!

Yes, it seems to me that it is a duplicate of #468 and ericblades comment seems reasonable. Here follows the full stack-trace from console: Error: EINVAL: invalid argument, uv_interface_addresses at Error (native) at /usr/lib/node_modules/ember-cli/node_modules/portfinder/lib/portfinder.js:395:23 at Object. (/usr/lib/node_modules/ember-cli/node_modules/portfinder/lib/portfinder.js:410:2) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (/usr/lib/node_modules/ember-cli/lib/commands/serve.js:7:19)

I checked the portfinder.js code and tracked it to the "os" api of node.js, since this is the native part of nodejs I did not follow it further and @ericblade is probably right.

If someone knows how to properly verify that it is the ifconfig issue then both this and #468 cloud be removed/merged into the root-cause.

choclaudio avatar Aug 23 '16 23:08 choclaudio

I almost forgot, I also did a test running this code directly with node: const os = require('os'); console.log(os.networkInterfaces());

The stacktrace for that: Error: EINVAL: invalid argument, uv_interface_addresses at Error (native) at Object. (/mnt/d/test.js:2:16) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Function.Module.runMain (module.js:441:10) at startup (node.js:139:18) at node.js:974:3

choclaudio avatar Aug 24 '16 00:08 choclaudio

Checking the node.js source code: https://github.com/nodejs/node/blob/master/src/node_os.cc

Method: static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args)

contains this particular code:

  int err = uv_interface_addresses(&interfaces, &count);

  ret = Object::New(env->isolate());

  if (err == UV_ENOSYS) {
    return args.GetReturnValue().Set(ret);
  } else if (err) {
    return env->ThrowUVException(err, "uv_interface_addresses");
  }

As far as I understand node.js relies on libuv for these operations, you can find the "uv_interface_addresses" there (http://docs.libuv.org/en/v1.x/misc.html).

The source code for the method can be found here: https://github.com/libuv/libuv/blob/7a19a48df8/src/unix/linux-core.c#L741

It is clear from this source code that it extensivly uses ifconfig information hence again strengthening the case made by @ericblade

These are some related comments: https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13383789-enable-network-interface-enumeraration

choclaudio avatar Aug 24 '16 00:08 choclaudio

Some news? 😞

felipefialho avatar Sep 27 '16 14:09 felipefialho

Nope, after my initial investigation into the issue I have not received any further feedback, not even on my actual findings.

choclaudio avatar Sep 27 '16 16:09 choclaudio

There are a lot of issues about this question since april.

It's unbelievable the problem doesn't have been resolved.

felipefialho avatar Sep 27 '16 16:09 felipefialho

Looks like this may be being worked on.

https://wpdev.uservoice.com/forums/266908-command-prompt-console-bash-on-ubuntu-on-windo/suggestions/13383789-enable-network-interface-enumeraration

SpazJibo avatar Oct 11 '16 02:10 SpazJibo

@JasonLinMS as FYI.

@cjibo Yes, it is being worked on. But, no ETA at the moment.

sunilmut avatar Oct 11 '16 18:10 sunilmut

@sunilmut Any update on when this might be fixed? Currently I need to work around this using dirty hacks :(

saschagehlich avatar Nov 07 '16 15:11 saschagehlich

@saschagehlich Should be this week for the Insider fast ring. I'll let you know if there are any changes to the schedule from the release team.

JasonLinMS avatar Nov 08 '16 02:11 JasonLinMS

Just an update that 'ifconfig' and the 'ip' commands for network enumeration should be working in the latest fast insider build 14965, also see release notes

sunilmut avatar Nov 10 '16 00:11 sunilmut

Closing this out since this has been marked fixed for sometime. If the issue persists, please reopen.

sunilmut avatar Nov 18 '16 05:11 sunilmut