Client.withBatch leaves per-request tasks pending when transport.send throws
维护者通常 2 天内回复
评估
调研方向
Start with Client.withBatch(), Batch.addRequest(), and the single request Client.send() failure path described in the issue; use the existing MockTransport to reproduce the send failure with two Ping requests. Trace how pending request registration and continuation resumption are coordinated, including exactly-once cleanup. Done when each affected task receives the send error, its pending entry is removed, and unrelated requests remain unaffected.
由索引模型根据 Issue 内容生成。
描述
Client.withBatch() propagates a transport send error to its caller, but does not propagate that failure to the tasks previously returned by Batch.addRequest().
How to found
After successfully connecting a client:
- Configure the transport to throw from
send()before delivering the batch, while keeping the receive stream open. - Add two requests inside
withBatch()and retain their returned task handles. - Catch the error thrown by
withBatch(). - Await the retained tasks without disconnecting or explicitly cancelling their requests.
The batch was not delivered, so no responses will arrive. However, the per-request tasks have no send-failure path that completes them.
This can be exercised using the existing MockTransport: complete initialization successfully, call setFailSend(true), then submit a batch of Ping requests.
Expected behavior
When sending the batch fails, its outstanding per-request tasks should complete with the send error, and their pending request entries should be removed.
Current code path
Batch.addRequest() returns an independent task that waits on a CheckedContinuation. Registration in pendingRequests happens through another asynchronous task:
Task {
await client.addPendingRequest(
id: request.id,
continuation: continuation,
type: M.Result.self
)
}
withBatch() subsequently sends the collected requests:
let data = try encoder.encode(requests)
try await connection.send(data)
There is no failure handler here to remove those pending requests or resume their continuations. Throwing from withBatch() does not automatically complete the separately created tasks.
By comparison, the single-request Client.send() path explicitly removes its pending request and resumes its continuation when sending fails.
Impact
Code awaiting the retained batch task results can remain suspended after the outer batch call has already failed. Registered pending requests also remain retained until another path handles them, such as explicit request cancellation or client disconnection.
This report concerns local transport send failure with no response received. It does not concern a successfully delivered batch containing JSON-RPC error responses, which already has response-handling logic.
my suggestion
I think withBatch() should propagate a send failure to all still-pending requests belonging to that batch, without affecting unrelated requests.
The fix also needs to account for asynchronous registration in Batch.addRequest(): simply removing currently registered IDs in a catch block may miss a continuation registered after cleanup. Registration and failure handling should be coordinated, while preserving exactly-once continuation resumption.
Related work
- #113 provides relevant exactly-once cleanup behavior for individual requests and response handling, but does not add batch send-failure cleanup.
- #210 and #213 change
withBatch()to return the closure’s result; their diffs leave the transport send-failure path without cleanup. - #314 adds rejection of batching for its modern protocol mode, rather than repairing failure handling in the existing batching path.
I did not find an existing issue or PR specifically addressing this failure path in the searches performed. If this issue and repair directions are correct, I am willing to open a PR.
- 主要语言
- Swift
- 星标
- 1.6k
- 派生
- 270
- 平均合并
- 2 天 7 小时
- 30 天内合并 PR
- 15
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/swift-sdk 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 73/100
modelcontextprotocol/swift-sdk#327 ·
维护者通常 2 天内回复
-
Value decoding changes data-URL-looking JSON strings into Value.data可能已有人在做 @bitbemol 于 73 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/swift-sdk#277 ·
维护者通常 2 天内回复
-
enhancement
难度 1/5 1 小时以内 新手友好度 78/100
modelcontextprotocol/swift-sdk#274 ·
维护者通常 2 天内回复
-
`HTTPClientTransport` fails to build on Windows: `#if !os(Linux)` guards no longer match the `EventSource` platform condition可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
modelcontextprotocol/swift-sdk#261 ·
维护者通常 2 天内回复
-
NetworkTransport drops a JSON message when a TCP receive contains a heartbeat followed by the message可能已有人在做 @bbdu3 于 4 天前认领。 未关闭bug
难度 3/5 1-2 天 新手友好度 25/100
modelcontextprotocol/swift-sdk#322 ·
维护者通常 2 天内回复
查看 modelcontextprotocol/swift-sdk 的全部 Issue
相似的 Issue
-
🎉 Add Ginkgo可能已有人在做 @usual2970 今天认领。 未关闭addition
难度 1/5 1 小时以内 新手友好度 76/100
jaywcjlove/awesome-mac#4442 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
DeveloperAcademy-POSTECH/2026-C6-A03-KIIKICK-iOS#76 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 91/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
-
难度 2/5 1-3 小时 新手友好度 78/100
VictorKildahl/cra#302 · 1 条评论 ·
维护者通常 1 天内回复