fix: don't block on creating the SSE stream (#553)

This commit is contained in:
Jack Amadeo 2025-11-19 20:20:00 -05:00 • committed by GitHub
commit da57ee7697
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -391,47 +391,51 @@ impl<C: StreamableHttpClient> Worker for StreamableHttpClientWorker<C> {
} }
let mut streams = tokio::task::JoinSet::new(); let mut streams = tokio::task::JoinSet::new();
if let Some(session_id) = &session_id { if let Some(session_id) = &session_id {
match self let client = self.client.clone();
.client let uri = config.uri.clone();
.get_stream( let session_id = session_id.clone();
config.uri.clone(), let auth_header = config.auth_header.clone();
session_id.clone(), let retry_config = self.config.retry_config.clone();
None, let sse_worker_tx = sse_worker_tx.clone();
config.auth_header.clone(), let transport_task_ct = transport_task_ct.clone();
) let config_uri = config.uri.clone();
.await let config_auth_header = config.auth_header.clone();
{
Ok(stream) => { streams.spawn(async move {
let sse_stream = SseAutoReconnectStream::new( match client
stream, .get_stream(uri.clone(), session_id.clone(), None, auth_header.clone())
StreamableHttpClientReconnect { .await
client: self.client.clone(), {
session_id: session_id.clone(), Ok(stream) => {
uri: config.uri.clone(), let sse_stream = SseAutoReconnectStream::new(
auth_header: config.auth_header.clone(), stream,
}, StreamableHttpClientReconnect {
self.config.retry_config.clone(), client: client.clone(),
); session_id: session_id.clone(),
streams.spawn(Self::execute_sse_stream( uri: config_uri,
sse_stream, auth_header: config_auth_header,
sse_worker_tx.clone(), },
false, retry_config,
transport_task_ct.child_token(), );
)); Self::execute_sse_stream(
tracing::debug!("got common stream"); sse_stream,
sse_worker_tx,
false,
transport_task_ct.child_token(),
)
.await
}
Err(StreamableHttpError::ServerDoesNotSupportSse) => {
tracing::debug!("server doesn't support sse, skip common stream");
Ok(())
}
Err(e) => {
// fail to get common stream
tracing::error!("fail to get common stream: {e}");
Err(e)
}
} }
Err(StreamableHttpError::ServerDoesNotSupportSse) => { });
tracing::debug!("server doesn't support sse, skip common stream");
}
Err(e) => {
// fail to get common stream
tracing::error!("fail to get common stream: {e}");
return Err(WorkerQuitReason::fatal(
e,
"get general purpose event stream",
));
}
}
} }
loop { loop {
let event = tokio::select! { let event = tokio::select! {