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

DefaultSleeper.close can strand pending sleepAsync futures

Aperta
#889 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
java, kotlin
Ambito
api

Direzione di ricerca

Inizia da DefaultSleeper.sleepAsync() e close(), quindi esamina come RetryingHttpClient compone la richiesta successiva a partire dal future di sleep. Aggiungi una copertura di regressione che dimostri che i future in sospeso vengono risolti alla chiusura, che gli sleep completati non lasciano tracciamenti in sospeso, che le chiamate ripetute a close() sono sicure e che sleepAsync() restituisce un future risolto dopo la chiusura.

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

Descrizione

Description

DefaultSleeper.sleepAsync() schedules a TimerTask that completes a CompletableFuture, while close() only cancels the underlying Timer:

override fun close() = timer.cancel()

Timer.cancel() discards scheduled tasks that have not yet run. Their associated futures are not completed or cancelled.

A caller waiting on one of those futures can therefore wait forever after the sleeper is closed. In the SDK this can happen while an async retry is in backoff: RetryingHttpClient composes the next request from sleeper.sleepAsync(backoffDuration), so closing the client during that delay can strand the request future.

Expected behavior

Closing DefaultSleeper should deterministically settle every pending async sleep future rather than abandoning it.

Suggested fix

Track pending timer tasks/futures. On close, cancel the timer and complete or cancel each pending future. Tasks that run normally should remove themselves from the pending set.

The close path should be idempotent, and a post-close sleepAsync() call should return an already-failed/cancelled future rather than throwing synchronously from Timer.schedule.

Regression coverage

  • close settles a long pending sleepAsync() future promptly;
  • normally completed sleeps are removed from pending tracking;
  • repeated close is safe;
  • sleepAsync() after close returns a settled exceptional/cancelled future instead of throwing synchronously.
Lingua principale
Kotlin
Stelle
1.5k
Fork
264
Merge medio
13h 31m
PR unite (30g)
89

Guida per i contributori

Apri la guida per i contributori

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.