From 4b1dd0f921ddce2a34221ca8f21cbed876a8c4fe Mon Sep 17 00:00:00 2001 From: Wei Hu <105701970+sowhu@users.noreply.github.com> Date: Mon, 30 May 2022 23:39:32 +0800 Subject: [PATCH] Fix a possible test hang in runtime::test_shared_buffer_sweep (#25545) * Fix a possible test hang in runtime::test_shared_buffer_sweep The test may hang if the total number of threads it wants to start is greater than the number of threads configured in the rayon threadpool. Check to avoid this situation from happening. * Incorporate comment from Xiang Zhu, using std::cmp::min() to simplify the code --- runtime/src/shared_buffer_reader.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/src/shared_buffer_reader.rs b/runtime/src/shared_buffer_reader.rs index c6251d202e..59b57efef4 100644 --- a/runtime/src/shared_buffer_reader.rs +++ b/runtime/src/shared_buffer_reader.rs @@ -844,7 +844,9 @@ pub mod tests { let parallel_reader = reader_ct > 2; let handle = if parallel_reader { - let threads = 8; + // Avoid to create more than the number of threads available in the + // current rayon threadpool. Deadlock could happen otherwise. + let threads = std::cmp::min(8, rayon::current_num_threads()); Some({ let parallel = (0..threads) .into_iter()