Skip to content

fix: handle SSE transport send errors after SSE disconnects#1733

Open
MumuTW wants to merge 1 commit into
modelcontextprotocol:mainfrom
MumuTW:fix/sse-transport-crash-1014
Open

fix: handle SSE transport send errors after SSE disconnects#1733
MumuTW wants to merge 1 commit into
modelcontextprotocol:mainfrom
MumuTW:fix/sse-transport-crash-1014

Conversation

@MumuTW

@MumuTW MumuTW commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • catch rejected webAppTransport.send() promises in the stdio stderr handler
  • keep transport cleanup in .finally() for the MODULE_NOT_FOUND path so cleanup still runs if the SSE client already disconnected
  • avoid unhandled Not connected rejections when multiple SSE connections race and one closes before stderr forwarding completes

Testing

  • npm ci
  • npm run build-server

Fixes #1014.

Supersedes the earlier stale attempt in #1129.

…ontextprotocol#1014)

When the SSE connection is closed (e.g. client disconnects during rapid
reconnection), webAppTransport.send() rejects with "Not connected".
The stderr handler was calling send() without awaiting or catching the
returned promise, causing unhandled rejections that crash the server.

Add .catch() to both send() call sites in the stderr data handler so
that errors from a closed SSE connection are silently ignored instead
of crashing the process. Also move the cleanup logic in the
MODULE_NOT_FOUND branch into .finally() so transports are cleaned up
regardless of whether the notification send succeeded.
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.

SSE transport crashes with "Not connected" error when multiple connections occur

1 participant