Skip to content

Fix SIGTRAP crash from continuation misuse in connection handling - #151

Merged
mattt merged 1 commit into
mattt:mainfrom
sciencemanx:fix/connection-crash
Sep 2, 2026
Merged

mattt merged 1 commit into
mattt:mainfrom
sciencemanx:fix/connection-crash

Conversation

@sciencemanx

@sciencemanx sciencemanx commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • The MCP SDK's NetworkTransport has reconnection logic that creates unstructured tasks holding CheckedContinuation references. For server-side incoming connections, this reconnection path can cause a double-resume when connections are cancelled, crashing the app with SIGTRAP
  • Disable reconnection and heartbeats for server-accepted connections since they are client features — if a client disconnects, it should reconnect itself
  • Make removeConnection idempotent to prevent stop() being called twice on the same connection

Context

Crash report shows:

SWIFT TASK CONTINUATION MISUSE: connect() leaked its continuation without resuming it.
SWIFT TASK CONTINUATION MISUSE: connect() tried to resume its continuation more than once,
  throwing [-32603] Internal error: Connection cancelled!

This occurs when Claude Desktop opens 25+ simultaneous connections via Bonjour.

Test plan

  • Launch iMCP and connect from Claude Desktop
  • Verify connections establish without SIGTRAP crash
  • Verify the app stays running when clients disconnect and reconnect
  • Verify tool calls still work through established connections

🤖 Generated with Claude Code

The MCP SDK's NetworkTransport has reconnection logic that creates
unstructured tasks holding CheckedContinuation references. For
server-side incoming connections, this reconnection path can cause
double-resume when connections are cancelled, crashing the app.

Disable reconnection and heartbeats for server-accepted connections
since they are client features — if a client disconnects, it should
reconnect itself. Also make removeConnection idempotent to prevent
stop() being called twice on the same connection.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@sciencemanx

Copy link
Copy Markdown
Contributor Author

I was seeing crashes when trying to connect claude desktop to the MCP (after I enabled and tried to do messages stuff) -- had claude debug and with this I no longer crash and am able to use successfully.

@mattt

mattt commented Sep 2, 2026

Copy link
Copy Markdown
Owner

Hi @sciencemanx. Sorry for leaving this sitting so long. Disabling the client-side reconnect and heartbeat on server-accepted connections is clearly right, and the idempotent removeConnection guard is a good belt-and-braces. Merging now, and I'll cut a release once a couple of the other stability fixes land.

@mattt
mattt merged commit 9436cfc into mattt:main Sep 2, 2026
toonvl added a commit to toonvl/iMCP that referenced this pull request Sep 2, 2026
Brings in the six upstream commits behind #2: the SIGTRAP
continuation fix (mattt#151), the Bonjour browser cleanup (mattt#199), the approval
setup-timeout exemption (mattt#200), the events_fetch date-only fix (mattt#175),
Madrid 0.5.0 with FetchRequest<Message> (mattt#201), and message read status
(mattt#195).

Three files conflicted, all because upstream shipped its own version of a
fix this fork already carried:

- CLI/main.swift: took upstream. Its mattt#199 supersedes our inline
  browser.cancel() (our closed upstream PR mattt#196) by extracting
  BonjourDiscovery.discoverEndpoint, which cancels on every exit path and
  comes with tests.
- App/Extensions/Foundation+Extensions.swift: took upstream. Its
  `count > 10` guard on the timezone-suffix regex is equivalent to our
  `!isDateOnlyISO8601String(...)`; staying identical to upstream is worth
  more than the marginal precision.
- App/Services/Calendar.swift: kept ours. Upstream only annotates
  `identifier` on the events_fetch and events_create returns, which our
  private encode(_:) helper already does alongside organizedByMe,
  organizer, isRecurring and coordinates.

Co-Authored-By: Claude Opus 5 <[email protected]>
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