Introduce a Semaphore
to fully honor RUSTUP_CONCURRENT_DOWNLOADS
#4455
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thatn
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 alwaysn
downloads happening concurrently.For reference, I leave below a small animation of the old (faulty) behavior:
... and the new (corrected) behavior: