fix: drop provider before getting the next one on range queries (#10034)

This commit is contained in:
joshieDo
2024-08-02 21:10:31 +01:00
committed by GitHub
parent d3ae2b7d73
commit 721e732e46

View File

@ -866,6 +866,12 @@ impl StaticFileProvider {
}; };
return Err(err) 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)?; provider = get_provider(number)?;
cursor = provider.cursor()?; cursor = provider.cursor()?;
retrying = true; retrying = true;
@ -898,14 +904,19 @@ impl StaticFileProvider {
self.get_segment_provider_from_transaction(segment, start, None) 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| { 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), Some(result) => Some(result),
None => { None => {
provider = get_provider(number).ok()?; // There is a very small chance of hitting a deadlock if two consecutive static
get_fn(&mut provider.cursor().ok()?, number).transpose() // 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()
} }
} }
})) }))