Skip to content

Commit 8a57765

Browse files
4t145Copilot
andauthored
fix: streamable http server close request channel on response(#266) (#270)
* fix: improve resource unregistration logic in LocalSessionWorker * fix: fix typo Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent 4c34b64 commit 8a57765

File tree

1 file changed

+11
-3
lines changed
  • crates/rmcp/src/transport/streamable_http_server/session

1 file changed

+11
-3
lines changed

crates/rmcp/src/transport/streamable_http_server/session/local.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,19 @@ impl LocalSessionWorker {
328328
if let Some(http_request_id) = self.resource_router.remove(resource) {
329329
tracing::trace!(?resource, http_request_id, "unregister resource");
330330
if let Some(channel) = self.tx_router.get_mut(&http_request_id) {
331-
channel.resources.remove(resource);
332-
if channel.resources.is_empty() {
331+
// It's okey to do so, since we don't handle batch json rpc request anymore
332+
// and this can be refactored after the batch request is removed in the coming version.
333+
if channel.resources.is_empty() || matches!(resource, ResourceKey::McpRequestId(_))
334+
{
333335
tracing::debug!(http_request_id, "close http request wise channel");
334-
self.tx_router.remove(&http_request_id);
336+
if let Some(channel) = self.tx_router.remove(&http_request_id) {
337+
for resource in channel.resources {
338+
self.resource_router.remove(&resource);
339+
}
340+
}
335341
}
342+
} else {
343+
tracing::warn!(http_request_id, "http request wise channel not found");
336344
}
337345
}
338346
}

0 commit comments

Comments
 (0)