Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Cancelling the completable future of an OpenAI call doesn't cancel the underlying OkHttp request

オープン
#654 コメント 6 件 リアクション 2 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@goutamadwant がすでに取り組んでいます。

2026年6月14日 から。

  • #759 @goutamadwant による — オープン

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
静か
技術スタック
kotlin
領域
api, backend

調査の方向性

示されている executeAsync ブリッジから始め、newCall(...).enqueue が CompletableFuture を基盤となる Call にどのように接続しているかを追跡します。現在キャンセルがどのように処理されているかを確認し、関連する非同期 HTTP テストを特定します。返された future をキャンセルするとリクエストもキャンセルされ、通常のレスポンス完了や失敗完了が損なわれなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

bug sdk

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

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/openai-java のほかの issue

openai/openai-java の issue をすべて見る

似ている issue

Kotlin の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。