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

fix: use 30s default for timeout as per README #20

Closed
wants to merge 1 commit into from

Conversation

h4l
Copy link
Contributor

@h4l h4l commented Feb 4, 2020

What / Why

The README specifies that the default for the timeout option is 30 seconds, but in reality no default is set. This seems to result in the timeout depending on the OS's default TCP socket timeouts which can be very long.

Background

I've been experiencing $ npm install occasionally hanging for long periods of time in docker image builds. When enabling --verbose  I see most npm http fetch * lines taking < 200ms but occasionally requests take more like 10 seconds, and less commonly hang for 5 minutes or so.

I assumed this was due to too much exponential backoff from the retry module, but in looking into this I noticed that npm doesn't document a timeout option (although setting a timeout in npm config does work), or explicitly specify a timeout when using this module, and this module's specified default of 30 seconds is not actually used in practice – no default is currently defined.

The default exponential backoff from the fetch-retry-* settings imply a 10s pause after the first failure, then a 60s pause after the second failure, followed by a final attempt. This contributes to some of the time spent hanging, but not all of it. The long timeouts on each of the 3 possible failing fetches mean it can take many minutes for a fetch to actually fail.

With the 30s default timeout, a fetch should take at most 2m40s to fail (30 + 10 + 30 + 60 + 30).

References

@h4l
Copy link
Contributor Author

h4l commented Feb 5, 2020

Build seems to be failing from 42f998. isFromCI is still true after setting process.env.CI to false because ciDetect() returns a truthy value if the TRAVIS envar is set, which it is in the CI build.

@h4l
Copy link
Contributor Author

h4l commented Feb 5, 2020

Here's an example from npm install --verbose running in a docker image build which gets stuck for ~7 minutes:

[...]
npm http fetch GET 200 https://registry.npmjs.org/array-equal/-/array-equal-1.0.0.tgz 63ms
npm http fetch GET 200 https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz 83ms
npm http fetch GET 200 https://registry.npmjs.org/@lib.cam/xslt-nailgun/-/xslt-nailgun-0.2.1.tgz 6421ms
npm http fetch GET 200 https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz 3277ms
npm http fetch GET 200 https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz 2366ms
npm http fetch GET 200 https://registry.npmjs.org/fsevents/-/fsevents-1.2.9.tgz 1633ms
npm http fetch GET 200 https://registry.npmjs.org/core-js/-/core-js-3.6.4.tgz 1216ms
npm http fetch GET 200 https://registry.npmjs.org/core-js/-/core-js-2.6.10.tgz 1141ms
npm http fetch GET 200 https://registry.npmjs.org/typescript/-/typescript-3.7.5.tgz 7894ms
npm http fetch GET 200 https://registry.npmjs.org/rxjs/-/rxjs-6.5.3.tgz 5761ms
npm http fetch GET 200 https://registry.npmjs.org/right-align/-/right-align-0.1.3.tgz 409712ms attempt #2
npm http fetch GET 200 https://registry.npmjs.org/decamelize-keys/-/decamelize-keys-1.1.0.tgz 409640ms attempt #2
npm timing action:extract Completed in 416474ms
npm timing action:finalize Completed in 793ms
npm timing action:refresh-package-json Completed in 1583ms
npm info lifecycle semver@5.7.1~preinstall: semver@5.7.1
npm info lifecycle source-map@0.5.7~preinstall: source-map@0.5.7
[...]

This was running in the node:12-alpine image:

/ # npm --version
6.13.4
/ # node --version
v12.14.0

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

Successfully merging this pull request may close these issues.

1 participant