Skip to content

Invalid argument: family must be 4 or 6 #3413

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

Closed
lindaorny opened this issue Jun 15, 2021 · 15 comments
Closed

Invalid argument: family must be 4 or 6 #3413

lindaorny opened this issue Jun 15, 2021 · 15 comments

Comments

@lindaorny
Copy link

lindaorny commented Jun 15, 2021

  • Node.js Version: v8.16.2 with npm version 6.4.1
  • OS: Ubuntu 16.04.7 LTS
  • Scope (install, code, runtime, meta, other?): npm install
  • Module (and version) (if relevant): failed to install all module

I am installing nodejs on the machine built on top of openstack with ubuntu cloud image 16.04. However, it prompts "Invalid argument: family must be 4 or 6" whenever I type npm install.

I have googled a lot these days and have done a lot of trial and error but cannot find a workable solution... I am posting here and hoping that I can gather opinion to resolve the issue T.T which I really want to build a docker nodejs app but do not want to stuck here.

Below is the list of item that I have tried:
(1) Try to install nodejs version from v4 to v13

I installed the nodejs by the following steps:
apt-get method:

sudo apt-get update
# logout and login back to the server/reboot the server
sudo apt-get install nodejs
sudo apt-get install npm

which by default the nodejs version installed is v4.2.6. This allows me to perform npm install without the "Invalid argument: family must be 4 or 6" but the version of the modules is too old which is not compatible to my app requirement.

Install using a PPA

cd ~
curl -sL https://deb.nodesource.com/setup_8.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
sudo apt-get install nodejs

Install using nvm

sudo apt-get install build-essential libssl-dev
curl -sL https://github.com/raw/creationix/nvm/v0.33.8/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile 
nvm install v8.16.2

Then, I try the PPA installation and nvm installation method by creating new ubuntu 16.04 server over and over again (in case my previous installation by apt remove has not completely remove nodejs package). However, the same family 4 or 6 issue prompt out again when using node v8, v9, v10, v11, v12. Only the version under v8 does not have the issue but again I want v8 as I need v8 to compatible to my app.

(2) Try out different ubuntu image
I tried out ubuntu 16.04, 18.04 and 20.04 by using the point (1) installation method but still does not help so it does not related to my OS version

(3) Change the nodejs node setting

From https://github.com/nodejs/node/issues/8635

I try to remove the repository=http://registry.npmjs.org/npm in ~/.npmrc but no help

From https://npm.community/t/npm-install-g-typescript-fails-with-npm-err-the-value-false-is-invalid-for-option-readablehighwatermark/8668/3

I try to change the cache.js as suggested by madbiker88 under nodejs\node_modules\npm\make-fetch-happen\cache.js - line 12
const MAX_MEM_SIZE = 25 * 1024 * 1024 // 25MB my temp fix to allow large downloads
I have change the MAX_MEM_SIZE from 5 to 25 and run npm install but it does not help. The family 4 or 6 issue still exist.

From https://stackoverflow.com/questions/60049568/npm-error-the-value-4294967295-is-invalid-for-option-family

It said that it is related to the family options but I searched through all the files in the ubuntu machine but I cannot find the dns.js file

I searched through all the file in the ubuntu server that contain options.family string and

hard code the options.family under
`lib/node_modules/npm/node_modules/pacote/node_modules/make-fetch-happen/node_modules/agentkeepalive/lib/_http_agent.js`


if (options.family === 4 || options.family === 6)
    name += ':' + options.family;

to

if (options.family === 4 || options.family === 6)
    name = 4;


It does not help as well...

(4) I doubt if it related to ipv4 or ipv6 setting
The server orginally is configured with both ipv6 and ipv4 and I disable ipv6 on my ubuntu machine but still no help

(5) I doubt if the network speed is to slow to download packages
I set the npm install -timeout=9999999 but still no help

(6) I doubt if it is related to the openstack ubuntu cloud image issue
I extracted the raw format cloud image instead of qcow2 format to build the server and install node by using the steps at point(1) but still no help

Hope that anyone can help to give me some insight T.T

Thanks!

@bl-ue
Copy link

bl-ue commented Jun 15, 2021

It said that it is related to the family options but I searched through all the files in the ubuntu machine but I cannot find the dns.js file

dns.js is located here: https://github.com/nodejs/node/blob/master/lib/dns.js

I searched through all the file in the ubuntu server that contain options.family string and

These files are part of node core, so they're actually embedded inside of the node binary and thus aren't searchable. If you want to search for them, clone https://github.com/nodejs/node (git clone https://github.com/nodejs/node, then search them inside the node folder).

@lindaorny I'll try to investigate some more.

@lindaorny
Copy link
Author

lindaorny commented Jun 16, 2021

It said that it is related to the family options but I searched through all the files in the ubuntu machine but I cannot find the dns.js file

dns.js is located here: https://github.com/nodejs/node/blob/master/lib/dns.js

I searched through all the file in the ubuntu server that contain options.family string and

These files are part of node core, so they're actually embedded inside of the node binary and thus aren't searchable. If you want to search for them, clone https://github.com/nodejs/node (git clone https://github.com/nodejs/node, then search them inside the node folder).

@lindaorny I'll try to investigate some more.

Thanks @bl-ue!

I just think if we can amend the file inside the node binary that change the family option 4 or 6 and make the node binary executable. Then, I can be able to skip the error...

@bl-ue
Copy link

bl-ue commented Jun 16, 2021

What would be best is for me to see it myself. Could you perhaps enable SSH access on your VM, and send me the credentials here, or something like that? Being able to reproduce the issue myself would be so invaluable, I might be able to root it down.

(I'm going to bed now, so you might want to wait 9 hours before you do that, I'll be up by then.)

@bl-ue
Copy link

bl-ue commented Jun 16, 2021

I just think if we can amend the file inside the node binary that change the family option 4 or 6 and make the node binary executable. Then, I can be able to skip the error...

Maybe, but when @dmilith tried that it gave him a different strange error.

@bl-ue
Copy link

bl-ue commented Jun 16, 2021

ping @lindaorny I'm available now if you want to let me SSH in — I'll probably get it figured out in a few hours.

@lindaorny
Copy link
Author

lindaorny commented Jun 17, 2021

@bl-ue By looking into more details from the nodejs log

0 info it worked if it ends with ok
1 verbose cli [ '/home/ubuntu/.nvm/versions/node/v8.16.2/bin/node',
1 verbose cli   '/home/ubuntu/.nvm/versions/node/v8.16.2/bin/npm',
1 verbose cli   'install',
1 verbose cli   'express' ]
2 info using [email protected]
3 info using [email protected]
4 verbose config Skipping project config: /home/ubuntu/.npmrc. (matches userconfig)
5 verbose npm-session ca4d4398d4f08c34
6 silly install loadCurrentTree
7 silly install readLocalPackageData
8 silly fetchPackageMetaData error for express@latest Invalid argument: family must be 4 or 6
9 timing stage:rollbackFailedOptional Completed in 8ms
10 timing stage:runTopLevelLifecycles Completed in 2122ms
11 verbose stack TypeError: Invalid argument: family must be 4 or 6
11 verbose stack     at lookup (dns.js:129:11)
11 verbose stack     at net.js:1091:5
11 verbose stack     at defaultTriggerAsyncIdScope (internal/async_hooks.js:281:19)
11 verbose stack     at lookupAndConnect (net.js:1090:3)
11 verbose stack     at TLSSocket.Socket.connect (net.js:1025:5)
11 verbose stack     at Object.exports.connect (_tls_wrap.js:1088:12)
11 verbose stack     at HttpsAgent.createConnection (https.js:117:22)
11 verbose stack     at HttpsAgent.createSocket (/home/ubuntu/.nvm/versions/node/v8.16.2/lib/node_modules/npm/node_modules/agentkeepalive/lib/_http_agent.js:272:26)
11 verbose stack     at HttpsAgent.createSocket (/home/ubuntu/.nvm/versions/node/v8.16.2/lib/node_modules/npm/node_modules/agentkeepalive/lib/agent.js:77:11)
11 verbose stack     at HttpsAgent.addRequest (/home/ubuntu/.nvm/versions/node/v8.16.2/lib/node_modules/npm/node_modules/agentkeepalive/lib/_http_agent.js:243:10)
11 verbose stack     at new ClientRequest (_http_client.js:268:16)
11 verbose stack     at Object.request (http.js:39:10)
11 verbose stack     at request (https.js:245:15)
11 verbose stack     at fetch.Promise (/home/ubuntu/.nvm/versions/node/v8.16.2/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:54:17)
11 verbose stack     at new Promise (<anonymous>)
11 verbose stack     at fetch (/home/ubuntu/.nvm/versions/node/v8.16.2/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:41:10)
12 verbose cwd /home/ubuntu
13 verbose Linux 4.15.0-143-generic
14 verbose argv "/home/ubuntu/.nvm/versions/node/v8.16.2/bin/node" "/home/ubuntu/.nvm/versions/node/v8.16.2/bin/npm" "install" "express"
15 verbose node v8.16.2
16 verbose npm  v6.4.1
17 error Invalid argument: family must be 4 or 6
18 verbose exit [ 1, true ]

I added some logger to the file
/home/ubuntu/.nvm/versions/node/v8.16.2/lib/node_modules/npm/node_modules/agentkeepalive/lib/_http_agent.js

The execution stops at

const newSocket = self.createConnection(options, oncreate);

So the issue is related to the Socket when establishing connection. Then, I trace back the createConnection(options, oncreate) function. It called Agent.prototype.createConnection = net.createConnection; from the net.js file.

Then, I go through the code at the net.js file downloaded from the github repository for node version 8.16.2

net.js

module.exports = {
  _createServerHandle: createServerHandle,
  _normalizeArgs: normalizeArgs,
  _setSimultaneousAccepts,
  connect,
  createConnection: connect,
  createServer,
  isIP: cares.isIP,
  isIPv4: cares.isIPv4,
  isIPv6: cares.isIPv6,
  Server,
  Socket,
  Stream: Socket, // Legacy naming
};

and trace to the dns.lookup function... and I go to the dns.js file to look for the lookup function

function lookupAndListen(self, port, address, backlog, exclusive) {
  dns.lookup(address, function doListen(err, ip, addressType) {
    if (err) {
      self.emit('error', err);
    } else {
      addressType = ip ? addressType : 4;
      listenInCluster(self, ip, port, addressType,
                      backlog, undefined, exclusive);
    }
  });
}

At dns.js,

// Easy DNS A/AAAA look up
// lookup(hostname, [options,] callback)
function lookup(hostname, options, callback) {
  var hints = 0;
  var family = -1;
  var all = false;
  var verbatim = false;

  // Parse arguments
  if (hostname && typeof hostname !== 'string') {
    throw new TypeError('Invalid arguments: ' +
                        'hostname must be a string or falsey');
  } else if (typeof options === 'function') {
    callback = options;
    family = 0;
  } else if (typeof callback !== 'function') {
    throw new TypeError('Invalid arguments: callback must be passed');
  } else if (options !== null && typeof options === 'object') {
    hints = options.hints >>> 0;
    family = options.family >>> 0;
    all = options.all === true;
    verbatim = options.verbatim === true;

    if (hints !== 0 &&
        hints !== cares.AI_ADDRCONFIG &&
        hints !== cares.AI_V4MAPPED &&
        hints !== (cares.AI_ADDRCONFIG | cares.AI_V4MAPPED)) {
      throw new TypeError('Invalid argument: hints must use valid flags');
    }
  } else {
    family = options >>> 0;
  }

  if (family !== 0 && family !== 4 && family !== 6)
    throw new TypeError('Invalid argument: family must be 4 or 6');

dns.js

else if (typeof options === 'function') {
    callback = options;
    family = 0;
  }

It is suspected that the socketio fail to connect to the node repository.

@lindaorny
Copy link
Author

lindaorny commented Jun 17, 2021

When I reference
nodejs/node#19348

It seems that the nodejs behavior on the node built at openstack is strange.

On openstack,

~$ node
> a = undefined
undefined
> a >>> 0
4294967295

On vmware vm,

~$ node
> a = undefined
undefined
> a >>> 0
0

The value of a is different.. and 4294967295 is exactly the error flow when using nodejs v10.13.0
The value "4294967295" is invalid for option "family"

It can be one of the clue too...

@bl-ue
Copy link

bl-ue commented Jun 17, 2021

Ah, so perhaps family is getting set to 4294967295 🤔

@bl-ue
Copy link

bl-ue commented Jun 17, 2021

@lindaorny are you able to download files from GitHub and put them on OpenStack? I'll build a copy of node with some debugging in dns.js so we can see what's being passed to it, and where it's being passed the bad value.

The file should be about 50-60 MB.

@lindaorny
Copy link
Author

@lindaorny are you able to download files from GitHub and put them on OpenStack? I'll build a copy of node with some debugging in dns.js so we can see what's being passed to it, and where it's being passed the bad value.

The file should be about 50-60 MB.

Yes. I am able to download files from Github and put them on Openstack.

Sure. I will wait for your update.

Thanks a lot!

@bl-ue
Copy link

bl-ue commented Jun 18, 2021

To clarify: what exact command triggered the error?

@lindaorny
Copy link
Author

lindaorny commented Jun 18, 2021

To clarify: what exact command triggered the error?

I just installed the desired nodejs package. Perform npm init and npm install express.

The command is like below:

# After the installation of nodejs
npm init
# All press enter
npm install express

Just simply cannot install any package...

A side note: The network connection is completely fine as I can ping the nodejs repository and perform curl. And git clone without any issue.

@bl-ue
Copy link

bl-ue commented Jun 18, 2021

Ah, okay, that's all great info. I'll investigate tomorrow — I'm off now. Thank you! (the side note bit is really invaluable)

@lindaorny
Copy link
Author

@bl-ue any clue so far ...

@lindaorny
Copy link
Author

lindaorny commented Jun 28, 2021

@bl-ue Hey.. Just solved the issue which I feel really grateful... The issue is with the hypervisor behind openstack.

At first, I tried to compiled my own version of nodejs using the steps mentioned Building Node.js on supported platforms here. I added one line of code at dns.js to bypass the error and I can finally npm install the package on the machine.

However, it is not a really ideal solution as the compilation of customized nodejs takes time and we really do not know the root cause. It may cause issue afterwards.

Therefore, I have a deeper search on the internet. It seems it is related to QEMU bug. QEMU has floating point cast to int issue and the patch is at version 4.2. The steps is as shown Download QEMU. Again, the compilation takes time. I am not really understand why the compilation of QEMU need to be done on our own machine with the whole ./configure and make process.

The patch not really help or I am not very sure about the steps to install QEMU. I finally give up using QEMU and used KVM instead. I change the openstack compute base hypervisor to KVM and oopss... The calculation of undefined variable returns 0 not 4294967295...

Hope can help anyone future in need when deploying nodejs on openstack.

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

2 participants