From 59615eafac1f918863d03026b1ee4c1b310c1f5f Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Mon, 23 Nov 2026 05:20:25 +0800 Subject: [PATCH] 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. --- rust/lancedb/src/remote/client.rs | 35 ++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/rust/lancedb/src/remote/client.rs b/rust/lancedb/src/remote/client.rs index b16d0091d..e253535c7 100644 --- a/rust/lancedb/src/remote/client.rs +++ b/rust/lancedb/src/remote/client.rs @@ -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, /// User agent to use for requests. The default provides the library /// name and version. @@ -648,6 +650,14 @@ impl RestfulLanceDbClient { 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::::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::::resolve_blob_request_concurrency(Some( + super::Semaphore::MAX_PERMITS + )) + .unwrap(), + super::Semaphore::MAX_PERMITS + ); + } + use super::*; use serial_test::serial; use std::time::Duration;