mirror of
https://github.com/lancedb/lancedb.git
synced 2026-11-26 12:33:59 +00:00
fix: reject blob request concurrency above semaphore limit (#5160)
## Summary A `blob_request_concurrency` value above tokio's `Semaphore::MAX_PERMITS` reached `Semaphore::new` and panicked, aborting the process instead of reporting a configuration error. The value can come from explicit client configuration or `LANCE_CLIENT_BLOB_REQUEST_CONCURRENCY`, with a default of 8. Resolve the value with the existing precedence, preserve the existing zero and parse errors, and return `Error::InvalidInput` for values above `Semaphore::MAX_PERMITS`. The supported range is documented on `ClientConfig::blob_request_concurrency`. ## Tests Added a focused resolver test covering the maximum accepted value and one above it. The test passes an explicit value and does not mutate environment variables.
This commit is contained in:
@@ -87,7 +87,9 @@ pub struct ClientConfig {
|
||||
/// Maximum concurrent blob HTTP requests for this connection, shared by all
|
||||
/// tables and blob handles. Defaults to 8. The environment variable
|
||||
/// `LANCE_CLIENT_BLOB_REQUEST_CONCURRENCY` can also set this limit.
|
||||
/// The value must be greater than zero.
|
||||
/// The value must be between 1 and [`Semaphore::MAX_PERMITS`], inclusive.
|
||||
/// Values outside that range are rejected with [`Error::InvalidInput`] when
|
||||
/// the connection is created.
|
||||
pub blob_request_concurrency: Option<usize>,
|
||||
/// User agent to use for requests. The default provides the library
|
||||
/// name and version.
|
||||
@@ -648,6 +650,14 @@ impl RestfulLanceDbClient<Sender> {
|
||||
message: "blob request concurrency must be greater than zero".into(),
|
||||
});
|
||||
}
|
||||
if value > Semaphore::MAX_PERMITS {
|
||||
return Err(Error::InvalidInput {
|
||||
message: format!(
|
||||
"blob request concurrency must be at most {}, got {value}",
|
||||
Semaphore::MAX_PERMITS
|
||||
),
|
||||
});
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
@@ -1505,6 +1515,29 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// A semaphore cannot hold more than `MAX_PERMITS`, so a larger configured
|
||||
/// value is refused where it was set instead of panicking when the
|
||||
/// connection is created.
|
||||
#[test]
|
||||
fn test_blob_request_concurrency_must_fit_a_semaphore() {
|
||||
let error = RestfulLanceDbClient::<Sender>::resolve_blob_request_concurrency(Some(
|
||||
super::Semaphore::MAX_PERMITS + 1,
|
||||
))
|
||||
.expect_err("a concurrency above the semaphore limit must be refused");
|
||||
assert!(matches!(error, Error::InvalidInput { .. }));
|
||||
assert!(
|
||||
error.to_string().contains("blob request concurrency"),
|
||||
"{error}"
|
||||
);
|
||||
assert_eq!(
|
||||
RestfulLanceDbClient::<Sender>::resolve_blob_request_concurrency(Some(
|
||||
super::Semaphore::MAX_PERMITS
|
||||
))
|
||||
.unwrap(),
|
||||
super::Semaphore::MAX_PERMITS
|
||||
);
|
||||
}
|
||||
|
||||
use super::*;
|
||||
use serial_test::serial;
|
||||
use std::time::Duration;
|
||||
|
||||
Reference in New Issue
Block a user