Skip to content

Commit ab3bfb4

Browse files
committed
fix: fix hang by preventing stream.buffered(0) in concurrent downloads
1 parent b3ac2c9 commit ab3bfb4

File tree

4 files changed

+66
-2
lines changed

4 files changed

+66
-2
lines changed

src/cli/rustup_mode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ async fn check_updates(cfg: &Cfg<'_>, opts: CheckOpts) -> Result<utils::ExitCode
806806

807807
// Ensure that `.buffered()` is never called with 0 as this will cause a hang.
808808
// See: https://github.com/rust-lang/futures-rs/pull/1194#discussion_r209501774
809-
if num_channels > 0 {
809+
if channels_len > 0 {
810810
let multi_progress_bars =
811811
MultiProgress::with_draw_target(cfg.process.progress_draw_target());
812812
let semaphore = Arc::new(Semaphore::new(num_channels));

src/dist/manifestation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl Manifestation {
200200
.await
201201
}
202202
});
203-
if num_channels > 0 {
203+
if components_len > 0 {
204204
let results = component_stream
205205
.buffered(components_len)
206206
.collect::<Vec<_>>()

src/dist/manifestation/tests.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,33 @@ async fn remove_extensions_does_not_remove_other_components() {
13131313
assert!(utils::path_exists(cx.prefix.path().join("bin/rustc")));
13141314
}
13151315

1316+
#[tokio::test]
1317+
async fn remove_extensions_does_not_hang_with_concurrent_downloads_override() {
1318+
let cx = TestContext::with_env(
1319+
None,
1320+
GZOnly,
1321+
[("RUSTUP_CONCURRENT_DOWNLOADS".to_owned(), "2".to_owned())].into(),
1322+
);
1323+
1324+
let adds = vec![Component::new(
1325+
"rust-std".to_string(),
1326+
Some(TargetTriple::new("i686-apple-darwin")),
1327+
false,
1328+
)];
1329+
1330+
cx.update_from_dist(&adds, &[], false).await.unwrap();
1331+
1332+
let removes = vec![Component::new(
1333+
"rust-std".to_string(),
1334+
Some(TargetTriple::new("i686-apple-darwin")),
1335+
false,
1336+
)];
1337+
1338+
cx.update_from_dist(&[], &removes, false).await.unwrap();
1339+
1340+
assert!(utils::path_exists(cx.prefix.path().join("bin/rustc")));
1341+
}
1342+
13161343
#[tokio::test]
13171344
async fn add_and_remove_for_upgrade() {
13181345
let cx = TestContext::new(None, GZOnly);

tests/suite/cli_inst_interactive.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,43 @@ no active toolchain
262262
.is_ok();
263263
}
264264

265+
#[tokio::test]
266+
async fn with_no_toolchain_doesnt_hang() {
267+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
268+
run_input(
269+
&cx.config,
270+
&[
271+
"rustup-init",
272+
"--no-modify-path",
273+
"--default-toolchain=none",
274+
],
275+
"\n\n",
276+
)
277+
.is_ok();
278+
279+
cx.config.expect(["rustup", "check"]).await.is_err();
280+
}
281+
282+
#[tokio::test]
283+
async fn with_no_toolchain_doesnt_hang_with_concurrent_downloads_override() {
284+
let cx = CliTestContext::new(Scenario::SimpleV2).await;
285+
run_input(
286+
&cx.config,
287+
&[
288+
"rustup-init",
289+
"--no-modify-path",
290+
"--default-toolchain=none",
291+
],
292+
"\n\n",
293+
)
294+
.is_ok();
295+
296+
cx.config
297+
.expect_with_env(["rustup", "check"], [("RUSTUP_CONCURRENT_DOWNLOADS", "2")])
298+
.await
299+
.is_err();
300+
}
301+
265302
#[tokio::test]
266303
async fn with_non_default_toolchain_still_prompts() {
267304
let cx = CliTestContext::new(Scenario::SimpleV2).await;

0 commit comments

Comments
 (0)