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

Getting error - reason: connect ETIMEDOUT #8

Open
kennethchoe opened this issue Jul 26, 2018 · 6 comments
Open

Getting error - reason: connect ETIMEDOUT #8

kennethchoe opened this issue Jul 26, 2018 · 6 comments

Comments

@kennethchoe
Copy link

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 kennethchoe changed the title Getting error - reason: connect ETIMEOUT Getting error - reason: connect ETIMEDOUT Jul 26, 2018
@delfrrr
Copy link
Owner

delfrrr commented Jul 27, 2018

@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;

@kennethchoe
Copy link
Author

kennethchoe commented Jul 30, 2018

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.

@delfrrr
Copy link
Owner

delfrrr commented Aug 10, 2018

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)

const queue = new Queue(20, Infinity);

@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)

@kennethchoe
Copy link
Author

kennethchoe commented Aug 14, 2018

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.

@leemw1977
Copy link

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

@aisha9696
Copy link

aisha9696 commented Sep 18, 2019

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

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

No branches or pull requests

4 participants