Skip to content

Conversation

FranciscoTGouveia
Copy link
Contributor

Follow-up on #4450.

Although introducing the RUSTUP_CONCURRENT_DOWNLOADS environment variable allows the user to opt in to concurrency, there may be moments where this variable is not fully honored.

An example would be when installing a toolchain (6 components) and the user had RUSTUP_CONCURRENT_DOWNLOADS=2.
This would create some situations where there would only be one download being done, where two could have been downloaded instead; this situation has been reported here.

This is not a surprise as per the nature of the .buffered() method which, unfortunately, cannot ensure that n futures will always be buffered at a same point in time.

To overcome this, and ensure that the environment variable is honored at all times, I decided to introduce a Semaphore that guarantees that there are always n downloads happening concurrently.


For reference, I leave below a small animation of the old (faulty) behavior:

faulty

... and the new (corrected) behavior:

fixed

Copy link
Member

@rami3l rami3l left a comment

Choose a reason for hiding this comment

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

That's quite straightforward, thanks!

It might be interesting to introduce this to check_updates() as well.

…g "n" concurrent downloads

Using this environment variable with a value between 2 and 5 would mean
that concurrency was not being totally maximized as there could be less
than n futures running at a some point in time.
See:
https://docs.rs/futures-util/0.3.31/futures_util/stream/trait.StreamExt.html#method.buffered

Adding a semaphore allows US to control how many futures are running at
a time, fixing this problem and ensuring that the env var is always
honored and the downloads are maximizing concurrency.
@FranciscoTGouveia FranciscoTGouveia force-pushed the fix-concurrent-downloads branch from f2d788a to c61d1fc Compare August 25, 2025 16:47
@FranciscoTGouveia FranciscoTGouveia marked this pull request as ready for review August 26, 2025 13:33
@rami3l rami3l added this pull request to the merge queue Aug 26, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 26, 2025
@FranciscoTGouveia
Copy link
Contributor Author

I think this was just a spurious failure :/

@rami3l rami3l added this pull request to the merge queue Aug 26, 2025
Merged via the queue into rust-lang:master with commit 5f5ec19 Aug 26, 2025
29 checks passed
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.

2 participants