Skip to content

Release a request that around_request stops before its handler - #720

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
koic:release_a_request_that_around_request_stops_before_its_handler
Nov 27, 2026
Merged

koic merged 1 commit into
modelcontextprotocol:mainfrom
koic:release_a_request_that_around_request_stops_before_its_handler

Conversation

@koic

@koic koic commented Nov 27, 2026

Copy link
Copy Markdown
Member

Motivation and Context

A request is registered as in flight before it is dispatched, and the registration was released in an ensure inside the block that configuration.around_request wraps. A hook that raises before calling the request handler, or that returns without calling it, never ran that block, so the request stayed in flight after it had been answered.

This kept the request id from being used again on that session. Since a session with a request in flight is kept from idle expiry, it also kept the session from ever expiring, and with max_sessions: its slot from being given to another client.

The registration is now released around the instrumentation, whatever the hook does.

How Has This Been Tested?

test/mcp/server_cancellation_test.rb and test/mcp/server/transports/streamable_http_transport_test.rb. Against the previous library the request is still in flight after the hook refused it.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

## Motivation and Context

A request is registered as in flight before it is dispatched, and the registration was released in an `ensure` inside
the block that `configuration.around_request` wraps. A hook that raises before calling the request handler,
or that returns without calling it, never ran that block, so the request stayed in flight after it had been answered.

This kept the request id from being used again on that session. Since a session with a request in
flight is kept from idle expiry, it also kept the session from ever expiring, and with `max_sessions:` its slot from
being given to another client.

The registration is now released around the instrumentation, whatever the hook does.

## How Has This Been Tested?

`test/mcp/server_cancellation_test.rb` and `test/mcp/server/transports/streamable_http_transport_test.rb`.
Against the previous library the request is still in flight after the hook refused it.

## Breaking Changes

None.
@koic
koic merged commit 4b42ada into modelcontextprotocol:main Nov 27, 2026
13 checks passed
@koic
koic deleted the release_a_request_that_around_request_stops_before_its_handler branch November 27, 2026 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant