Repository navigation
Release a session in full when cancelling one of its requests raises - #721
Merged
Conversation
## Motivation and Context Ending a session cancels its requests in flight, wakes the threads waiting on its server-to-client requests, and closes its streams. A cancellation runs the `on_cancel` hooks of the request, and a hook that raises is handed to the exception reporter; when the reporter raises as well, the error leaves the cancellation. For a session ended on its own (`DELETE`, or a request that finds it expired), that error skipped everything after it: the requests not yet cancelled kept running, the waits were left to their timeout, and the streams stayed open, although the session was already gone from the registry and nothing would come back for them. Sessions that end together already had their streams closed whatever the cancellations did, but the sessions after the one that raised were not cancelled. Now such an error (a `StandardError`) no longer stops the rest: every request of every session is still cancelled, the waits are woken and the streams are closed, and the first error is raised once that is done. ## How Has This Been Tested? `test/mcp/server/transports/streamable_http_transport_test.rb`. Against the previous library the second request of the session is not cancelled. ## Breaking Changes None.
koic
deleted the
release_a_session_in_full_when_cancelling_one_of_its_requests_raises
branch
November 27, 2026 19:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Ending a session cancels its requests in flight, wakes the threads waiting on its server-to-client requests, and closes its streams. A cancellation runs the
on_cancelhooks of the request, and a hook that raises is handed to the exception reporter; when the reporter raises as well, the error leaves the cancellation.For a session ended on its own (
DELETE, or a request that finds it expired), that error skipped everything after it: the requests not yet cancelled kept running, the waits were left to their timeout, and the streams stayed open, although the session was already gone from the registry and nothing would come back for them. Sessions that end together already had their streams closed whatever the cancellations did, but the sessions after the one that raised were not cancelled.Now such an error (a
StandardError) no longer stops the rest: every request of every session is still cancelled, the waits are woken and the streams are closed, and the first error is raised once that is done.How Has This Been Tested?
test/mcp/server/transports/streamable_http_transport_test.rb. Against the previous library the second request of the session is not cancelled.Breaking Changes
None.
Types of changes
Checklist