You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A request whose session is terminated while it is admitted runs against the shared Server #704
A stateful Streamable HTTP request checks its session (validate_and_touch_session, lib/mcp/server/transports/streamable_http_transport.rb:2609) and then looks up its ServerSession in a second @mutex section (:2481). When a DELETE from another connection (or close) removes the session between the two, the lookup returns nil and dispatch_handle_json (:2601) falls back to the shared @server.handle_json. The tool runs with no session, so the session termination that #692 and #698 use to cancel the session's requests never reaches it, and the request is answered 200 with its result. Notifications have the same split between session_active? (:1948) and the lookup in dispatch_notification (:2338): a custom notification handler runs against the shared Server and the POST is answered 202.
To Reproduce
On main (00868f7), hold the request with a Queue barrier just after validate_and_touch_session (or session_active? for a notification) returns, send DELETE for the session, then release it:
A request that names a session and finds none when it looks the session up is answered 404 Session not found, as it is when the session is already gone at the check, and is not dispatched.
Logs
See above.
Additional context
The barrier only widens a window that exists between the two @mutex sections; a multi-threaded server can hit it without one. The effect is a handler running for a session that has ended, outside its cancellation; it does not skip the ownership check, which runs before both.
I have a fix with tests and will open a PR for it.
Activity
fix: refuse a request whose session ends while it is admitted