mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
fix(mcp): report ENOTCONN on stdio as a lost connection (#11490)
The CLI already treats ENOTCONN on stdout as a closed reader (#11275). The MCP transport classifier still reported it as an unknown transport error. It now shares one set of peer-gone codes: EPIPE, ECONNRESET and ENOTCONN. Fixes #11362
This commit is contained in:
1 parent
928b9df5c0
commit
11a7ac93cc
2 files changed
+18
-1
No files matched your search
@@ -19,6 +19,16 @@ const transportSystemCode = (error: unknown): string | undefined => {
|
||||
return typeof error.code === "string" ? error.code : undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* System codes that mean the peer has gone. A pipe reports EPIPE, a socket
|
||||
* ECONNRESET, and macOS can report ENOTCONN for a closed socket-pair stdio.
|
||||
*/
|
||||
const CONNECTION_LOST_CODES: ReadonlySet<string> = new Set([
|
||||
"EPIPE",
|
||||
"ECONNRESET",
|
||||
"ENOTCONN",
|
||||
]);
|
||||
|
||||
/** SDK error callbacks also report recoverable validation and protocol errors. */
|
||||
export const reportMcpTransportError = (
|
||||
error: unknown,
|
||||
@@ -29,7 +39,7 @@ export const reportMcpTransportError = (
|
||||
const diagnostic =
|
||||
error instanceof z.ZodError
|
||||
? { kind: "validation_error", message: MCP_VALIDATION_FAILED }
|
||||
: code === "EPIPE" || code === "ECONNRESET"
|
||||
: code !== undefined && CONNECTION_LOST_CODES.has(code)
|
||||
? { kind: "connection_lost", message: MCP_CONNECTION_LOST }
|
||||
: { kind: "unknown", message: MCP_TRANSPORT_ERROR };
|
||||
// Do not echo raw frames or exception text, which can contain caller data.
|
||||
|
||||
@@ -85,6 +85,13 @@ describe("MCP runtime errors", () => {
|
||||
cause: Object.assign(new Error("SECRET broken pipe"), { code: "EPIPE" }),
|
||||
message: MCP_CONNECTION_LOST,
|
||||
},
|
||||
{
|
||||
name: "a disconnected stdio socket",
|
||||
cause: Object.assign(new Error("SECRET not connected"), {
|
||||
code: "ENOTCONN",
|
||||
}),
|
||||
message: MCP_CONNECTION_LOST,
|
||||
},
|
||||
{
|
||||
name: "a wrapped HTTP broken pipe",
|
||||
cause: wrappedListenerDisconnect("EPIPE"),
|
||||
|
||||
Reference in new issue
Block a user