Cancelling the completable future of an OpenAI call doesn't cancel the underlying OkHttp request
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
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
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di openai/openai-java
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
openai/openai-java#886 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
openai/openai-java#802 · 2 commenti · 3 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
openai/openai-java#755 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
bug sdk
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
openai/openai-java#652 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 74/100
openai/openai-java#973 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di openai/openai-java
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
T31n/YagniLauncher#1051 ·
I maintainer di solito rispondono entro 1 giorno
-
Accepted Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
ankidroid/Anki-Android#22114 · 5 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
solana-foundation/pay-kit#341 ·
I maintainer di solito rispondono entro 1 giorno