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時間
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープン
難易度 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
-
[java] TestClassWithoutTestCases: document that abstract classes and interfaces are not checkedオープン
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
文件夹设置bugオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
joeseesun/qiaomu-jot#14 ·
メンテナーはふだん 1 日以内に返信
-
30-minutes algorithm any-language beginner-friendly c community cpp csharp data-structures go good first issue hacktoberfest help wanted kotlin learning leetcode php ruby rust swift
難易度 2/5 1時間未満 初心者へのやさしさ 85/100
Huerte/algo-solutions-python#211 ·
メンテナーはふだん 1 日以内に返信
-
area: build-and-ci S3: minor
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
manaflow-ai/cmux#39902 ·
メンテナーはふだん 1 日以内に返信