Cancelling the completable future of an OpenAI call doesn't cancel the underlying OkHttp request
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
示されている executeAsync ブリッジから始め、newCall(...).enqueue が CompletableFuture を基盤となる Call にどのように接続しているかを追跡します。現在キャンセルがどのように処理されているかを確認し、関連する非同期 HTTP テストを特定します。返された future をキャンセルするとリクエストもキャンセルされ、通常のレスポンス完了や失敗完了が損なわれなければ完了です。
索引モデルが issue の本文から書いたものです。
説明
I have a few scenarios where we may opportunistically issue a request to an LLM but then cancel it, sometimes quickly so potentially before it's even been processed by the backend and charged for. It would seem natural that using the cancel method of an async call would do that, but it doesn't appear that this propagates to the underlying OkHttp layer.
This method appears to be the bridge between the SDK interfaces and the underlying HTTP engine:
override fun executeAsync(
request: HttpRequest,
requestOptions: RequestOptions,
): CompletableFuture<HttpResponse> {
val future = CompletableFuture<HttpResponse>()
request.body?.run { future.whenComplete { _, _ -> close() } }
newCall(request, requestOptions)
.enqueue(
object : Callback {
override fun onResponse(call: Call, response: Response) {
future.complete(response.toResponse())
}
override fun onFailure(call: Call, e: IOException) {
future.completeExceptionally(OpenAIIoException("Request failed", e))
}
}
)
return future
}
The problem appears to be that the completable future here doesn't link to the HttpRequest. The Call interface from OkHttp has a cancel method, but this is not called as a result of the future being cancelled.
Instead what appears to happen is that the request is orphaned if the outer future is cancelled, leading to a resource leak.
- 主要言語
- Kotlin
- スター
- 1.5k
- フォーク
- 266
- 平均マージ
- 8時間 18分
- マージ済み PR(30日)
- 142
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
openai/openai-java のほかの issue
-
HttpRequest.url() logs spaces in path segments as literal plus signs対応中かも @sylvesterkaczmarek が 52 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
openai/openai-java#886 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Make diarized transcription duration and task optional対応中かも @wskr00 が 83 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
openai/openai-java#802 · コメント 2 件 · リアクション 3 件 ·
メンテナーはふだん 1 日以内に返信
-
AsyncStreamResponse can hang when the subscriber executor rejects work対応中かも @sylvesterkaczmarek が 35 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
openai/openai-java#973 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
openai/openai-java#956 ·
メンテナーはふだん 1 日以内に返信
-
Async internal plumbing bypasses both `dispatcherExecutorService` and `streamHandlerExecutor`, forcing a hop through `ForkJoinPool.commonPool()`対応中かも @sylvesterkaczmarek が 29 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
openai/openai-java#952 ·
メンテナーはふだん 1 日以内に返信
openai/openai-java の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
partiql/partiql-lang-kotlin#1972 ·
-
afk-ok area:data-quality importer size:S
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
enorm-labs/event-junkie#3027 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
libre-tube/LibreTube#8854 ·
メンテナーはふだん 1 日以内に返信