Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#654 6 commenti 2 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
kotlin
Ambito
api, backend

Direzione di ricerca

Parti dal bridge executeAsync mostrato e segui come newCall(...).enqueue collega la CompletableFuture al Call sottostante. Verifica come viene gestita attualmente la cancellazione e individua i test HTTP asincroni pertinenti; il lavoro è completato quando la cancellazione della future restituita cancella anche la richiesta senza compromettere il completamento normale della risposta o dell’errore.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Kotlin
Stelle
1.5k
Fork
264
Merge medio
13h 51m
PR unite (30g)
113

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openai/openai-java

Tutte le issue di openai/openai-java

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.