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

Specify TCP timeout when downloading packages #2950

Merged
merged 1 commit into from
Apr 5, 2017

Conversation

kirs
Copy link
Contributor

@kirs kirs commented Mar 18, 2017

It's been an old and annoying bug: yarn doesn't specify fetch timeout when downloading packages, causing yarn install to hang forever on network issues.

Steps to reproduce
  1. Install toxiproxy (proxy to simulate network latency [1], [2])
  1. Configure toxiproxy to simulate the latency:
~/.bin/toxiproxy-cli create yarnpkg --listen localhost:8888 -u registry.yarnpkg.com:443
~/.bin/toxiproxy-cli toxic add yarnpkg -t latency -a latency=9000 -a jitter=50
  1. Point yarn.lock to use localhost:8888 as a host for package registry

  2. Run yarn install and see the process hanging

The issue has been reported multiple times and it's a very easy fix; I'm surprised that I'm the first one to look into it. As mentioned in the fetch documentation, "requests to external servers should have a timeout attached".

Specifying timeout is a critical thing for distributed software and build tools. Earlier this week we found our build servers hanging on yarn install step for 40 minutes until it was hard killed. It took us a while to find that it was a network problem with connectivity between EC2 and registry.yarnpkg.com. Having the fetch timeout would help us to discover the issue and see the timeout error, as well as not causing build servers to hang until a hard kill.

fixes #764, #1289, #2351

@bestander

@bestander
Copy link
Member

Nice.
Could you fix lint issues?
Also how about making it a configuration parameter?
I wonder if 10 seconds may be too little for some cases.

I think there is huge need to write a test here but what would be your Test Plan for the change?

Copy link
Member

@bestander bestander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lint + test + config

@kirs
Copy link
Contributor Author

kirs commented Mar 20, 2017

Thanks for feedback! I'll work on it.

I wish RequestManager had better test coverage to have more examples how I can test it...

@bestander
Copy link
Member

Start with a manual Test Plan and think if this could be automated in some way

@bestander
Copy link
Member

It could be an e2e test with http requests mocked

@kirs kirs force-pushed the handle-timeout branch 4 times, most recently from dfeb004 to 8fa1482 Compare March 26, 2017 18:39
@kirs
Copy link
Contributor Author

kirs commented Mar 26, 2017

@bestander fixed lint, added the config option and the unit test 🎉

Random tests are failing on the CI but I can't reproduce them locally with the same version of node. Taking the fact that CI for master is also red, I assume the test suite is not 100% stable.

@kirs
Copy link
Contributor Author

kirs commented Apr 2, 2017

@bestander please let me know if there's something else I can improve.

@kirs kirs force-pushed the handle-timeout branch from 8fa1482 to 5174a9a Compare April 4, 2017 19:38
@kirs
Copy link
Contributor Author

kirs commented Apr 4, 2017

CircleCI is now green 🎉

@aliyazdani
Copy link

@kirs - thanks for this. Would love to see this merged in soon.

@bestander bestander merged commit b2c2c3b into yarnpkg:master Apr 5, 2017
@bestander
Copy link
Member

Great work, @kirs.
What do you think of implementing retries?
Would it be hard to have this feature in?

@kirs kirs deleted the handle-timeout branch April 5, 2017 23:32
@kirs
Copy link
Contributor Author

kirs commented Apr 5, 2017

Happy to see it merged!

@bestander in my implementation timeout errors are considered the same as other networking errors and they will be retried:

if (attempts < 5 && this.isPossibleOfflineError(err)) {

// TCP timeout

@kirs
Copy link
Contributor Author

kirs commented Apr 6, 2017

@casperisfine @stefanmb in case you've been wondering about Locutus builds stuck on yarn install... This fixes the issue.

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.

yarn install hangs during "Fetching packages..."
3 participants