Skip to content

Commit 70e959d

Browse files
committed
fix(http): disable idle connection pooling for default client
POST SSE response bodies cannot be fully consumed before the next request starts, causing reqwest to stall on pool checkout (~40ms). The long-lived GET SSE stream already holds its own connection, so there is no benefit to pooling POST connections with HTTP/1.1. This matches the workaround reported in #789.
1 parent c9ecfe0 commit 70e959d

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

crates/rmcp/src/transport/common/reqwest/streamable_http_client.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ impl StreamableHttpClientTransport<reqwest::Client> {
262262
/// This method requires the `transport-streamable-http-client-reqwest` feature.
263263
pub fn from_uri(uri: impl Into<Arc<str>>) -> Self {
264264
StreamableHttpClientTransport::with_client(
265-
reqwest::Client::default(),
265+
Self::default_http_client(),
266266
StreamableHttpClientTransportConfig {
267267
uri: uri.into(),
268268
auth_header: None,
@@ -277,7 +277,21 @@ impl StreamableHttpClientTransport<reqwest::Client> {
277277
///
278278
/// * `config` - The config to use with this transport
279279
pub fn from_config(config: StreamableHttpClientTransportConfig) -> Self {
280-
StreamableHttpClientTransport::with_client(reqwest::Client::default(), config)
280+
StreamableHttpClientTransport::with_client(Self::default_http_client(), config)
281+
}
282+
283+
/// Build the default reqwest client for this transport.
284+
///
285+
/// Disables idle connection pooling because POST SSE response bodies
286+
/// cannot be fully consumed before the next request starts, causing
287+
/// reqwest to stall on pool checkout (~40 ms). The long-lived GET
288+
/// SSE stream already holds its own connection, so there is no
289+
/// benefit to pooling POST connections with HTTP/1.1.
290+
fn default_http_client() -> reqwest::Client {
291+
reqwest::Client::builder()
292+
.pool_max_idle_per_host(0)
293+
.build()
294+
.expect("failed to build default reqwest client")
281295
}
282296
}
283297

0 commit comments

Comments
 (0)