Skip to content

mcp: don't let a best-effort cancel notify delay connection teardown - #1241

Open
arpankernel wants to merge 1 commit into
modelcontextprotocol:mainfrom
arpankernel:fix/connect-deadline-cleanup
Open

mcp: don't let a best-effort cancel notify delay connection teardown#1241
arpankernel wants to merge 1 commit into
modelcontextprotocol:mainfrom
arpankernel:fix/connect-deadline-cleanup

Conversation

@arpankernel

Copy link
Copy Markdown
Contributor

When a call is cancelled at its deadline, the best-effort notifications/cancelled is sent asynchronously (#1151), but Connection.Close still waited on that in-flight write for up to notifyCancellationTimeout against an unresponsive peer. So Connect could return well past its own deadline: 7s on a 2s deadline against a peer that accepts the TCP connection but never replies.

This adds a Closing signal to the jsonrpc2 connection and aborts the best-effort notify once teardown begins, so Connect returns within its deadline. Closing the connection already signals the cancellation, so waiting on the notify buys nothing.

Includes a black-hole regression test asserting Connect stays within its deadline (red before, green after).

Fixes #1189

When a call is cancelled at its deadline, the notifications/cancelled is
sent asynchronously, but Connection.Close's wait still blocked on that
in-flight write for up to notifyCancellationTimeout against an
unresponsive peer. Add a Closing signal to the jsonrpc2 connection and
abort the notify once teardown begins, so Connect returns within its own
deadline.

Fixes modelcontextprotocol#1189
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.

streamable client: Connect blocks far past its context deadline against an unresponsive server (detached-context cleanup)

1 participant