Skip to content

Fix MCP compatibility client shutdown deadlock - #308

Merged
JAORMX merged 1 commit into
mainfrom
fix/mcp-client-close-deadlock
Sep 25, 2026
Merged

JAORMX merged 1 commit into
mainfrom
fix/mcp-client-close-deadlock

Conversation

@JAORMX

@JAORMX JAORMX commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • release the compat-client mutex before waiting for go-sdk session shutdown
  • clear only the session snapshot that was closed, preserving concurrent-close and initialization safety
  • add a real go-sdk in-memory transport regression for notification-handler re-entry during shutdown

Root cause

Client.Close held c.mu while ClientSession.Close waited for active SDK notification handlers. A synchronous OnNotification callback re-entering ListPrompts then blocked on that mutex, deadlocking shutdown.

Validation

  • go test -race ./mcpcompat/client -run TestClientClose_DoesNotHoldMutexWhileNotificationHandlerDrains -count=1
  • task lint
  • task test
  • task

The new regression was also run against a temporary restoration of the affected implementation and failed because the callback could not re-enter the client; it passes with this change.

@JAORMX
JAORMX force-pushed the fix/mcp-client-close-deadlock branch from 951a355 to f70a8a5 Compare September 25, 2026 21:25
@JAORMX
JAORMX merged commit ac6446d into main Sep 25, 2026
6 checks passed
@JAORMX
JAORMX deleted the fix/mcp-client-close-deadlock branch September 25, 2026 21:39
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.

2 participants