From 721e732e46e68bc24bb9588b75a23fde4c0379e9 Mon Sep 17 00:00:00 2001 From: joshieDo <93316087+joshieDo@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:10:31 +0100 Subject: [PATCH] fix: drop `provider` before getting the next one on range queries (#10034) --- .../src/providers/static_file/manager.rs | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/storage/provider/src/providers/static_file/manager.rs b/crates/storage/provider/src/providers/static_file/manager.rs index c79a4dd71..ad813d6b8 100644 --- a/crates/storage/provider/src/providers/static_file/manager.rs +++ b/crates/storage/provider/src/providers/static_file/manager.rs @@ -866,6 +866,12 @@ impl StaticFileProvider { }; return Err(err) } + // There is a very small chance of hitting a deadlock if two consecutive + // static files share the same bucket in the + // internal dashmap and we don't drop the current provider + // before requesting the next one. + drop(cursor); + drop(provider); provider = get_provider(number)?; cursor = provider.cursor()?; retrying = true; @@ -898,14 +904,19 @@ impl StaticFileProvider { self.get_segment_provider_from_transaction(segment, start, None) } }; - let mut provider = get_provider(range.start)?; + let mut provider = Some(get_provider(range.start)?); Ok(range.filter_map(move |number| { - match get_fn(&mut provider.cursor().ok()?, number).transpose() { + match get_fn(&mut provider.as_ref().expect("qed").cursor().ok()?, number).transpose() { Some(result) => Some(result), None => { - provider = get_provider(number).ok()?; - get_fn(&mut provider.cursor().ok()?, number).transpose() + // There is a very small chance of hitting a deadlock if two consecutive static + // files share the same bucket in the internal dashmap and + // we don't drop the current provider before requesting the + // next one. + provider.take(); + provider = Some(get_provider(number).ok()?); + get_fn(&mut provider.as_ref().expect("qed").cursor().ok()?, number).transpose() } } }))