npm-consider icon indicating copy to clipboard operation
npm-consider copied to clipboard

Getting error - reason: connect ETIMEDOUT

Open kennethchoe opened this issue 7 years ago • 6 comments

Symptom

When I run npm-consider install, it goes through tens of packages and then at one point it gives ETIMEOUT. Every time I retry, it stops at different points.

Suggested Fix

Either retry, or expand timeout?

How to reproduce

I am using vue-cli.

vue create npm-consider-test
<<< click enter and then wait for a minute >>>
cd npm-consider-test
npm-consider install

Outputs I get

PS C:\temp\npm-consider-test> npm-consider install
[email protected]
GET https://registry.npmjs.org/p-limit{ FetchError: request to https://registry.npmjs.org/@babel%2fpreset-stage-2 failed, reason: connect ETIMEDOUT 104.16.20.35:443
    at ClientRequest.<anonymous> (C:\Users\kennethc\AppData\Roaming\npm\node_modules\npm-consider\node_modules\node-fetch\index.js:133:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'FetchError',
  message: 'request to https://registry.npmjs.org/@babel%2fpreset-stage-2 failed, reason: connect ETIMEDOUT 104.16.20.35:443',
  type: 'system',
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT' }
PS C:\temp\npm-consider-test> npm-consider install
[email protected]
GET https://registry.npmjs.org/run-queue{ FetchError: request to https://registry.npmjs.org/cssnano failed, reason: connect ETIMEDOUT 104.16.20.35:443
    at ClientRequest.<anonymous> (C:\Users\kennethc\AppData\Roaming\npm\node_modules\npm-consider\node_modules\node-fetch\index.js:133:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at TLSSocket.socketErrorListener (_http_client.js:387:9)
    at emitOne (events.js:116:13)
    at TLSSocket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:64:8)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  name: 'FetchError',
  message: 'request to https://registry.npmjs.org/cssnano failed, reason: connect ETIMEDOUT 104.16.20.35:443',
  type: 'system',
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT' }
PS C:\temp\npm-consider-test>

kennethchoe avatar Jul 26 '18 18:07 kennethchoe

@kennethchoe any chance you can fork it and play with timeout here https://github.com/delfrrr/npm-consider/blob/master/lib/getPackageDetails.js#L85 and here https://github.com/delfrrr/npm-consider/blob/master/lib/getPackageDetails.js#L107

Timeout can be set in node-fetch https://github.com/bitinn/node-fetch

If it works, I will add the parameter for timeout, if not, I will implement retry then;

delfrrr avatar Jul 27 '18 05:07 delfrrr

As non-hardcore-node developer, going through the code to test your suggestion out was very good exercise for me. Learned a lot of things.

Things you might want to know:

  1. I am using npm 5.6.0, which is up-to-date. I found some reports around ETIMEDOUT error suggesting you want to make sure you are using latest version of npm.

  2. I am not using proxy. Still, I ran the following commands.

npm config rm proxy
npm config rm https-proxy
  1. node-fetch's timeout option did not work. I learned that node-fetch will report the timeout error in different wording by looking at https://github.com/bitinn/node-fetch/blob/master/src/index.js/#L55-L67.
		if (options.timeout) {
			req.once('socket', function(socket) {
				reqTimeout = setTimeout(function() {
					req.abort();
					reject(new FetchError('network timeout at: ' + options.url, 'request-timeout'));
				}, options.timeout);
			});
		}

		req.on('error', function(err) {
			clearTimeout(reqTimeout);
			reject(new FetchError('request to ' + options.url + ' failed, reason: ' + err.message, 'system', err));
		});
  1. When it fails, it fails from a request made a while ago, not the last request. I made console.log on both occasions you pointed out. On one test, the output showed about 2000 requests to https://registry.npmjs.org before it reported ETIMEDOUT, and the one ETIMEDOUT error was reported at the end was actually for the 379th call.

I hope this helps.

kennethchoe avatar Jul 30 '18 15:07 kennethchoe

I tested ut a bit more and sometimes I would get ETIMEDOUT as well. I see two solutions:

quick one: decrease number of parallel requests (parallel threads in a queue, now =20)

https://github.com/delfrrr/npm-consider/blob/eba62db7c346d6dfaeb7e1b8d550e631a8d59c76/lib/walkDependencies.js#L58

@kennethchoe can you test if this helps?

Then, this number can be configured via parameters

Implement retry (this package looks promising https://github.com/jonbern/fetch-retry#readme)

delfrrr avatar Aug 10 '18 05:08 delfrrr

I tried with new Queue(1, Infinity);. It was much slower, of course, and still got the error eventually.

By the way, brilliant library it is - promise-queue.

kennethchoe avatar Aug 14 '18 15:08 kennethchoe

I've started taking a look into fetch retry that @delfrrr mentioned above, will keep you posted.

leemw1977 avatar Dec 22 '18 07:12 leemw1977

In windows 10 -> Settings -> Internet and Networks ->Proxy you'll find proxy, so set that proxy using this commands npm config set proxy _your proxy_ npm config set https-proxy _your proxy_ It works for me

aisha9696 avatar Sep 18 '19 05:09 aisha9696