Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

DefaultSleeper.close can strand pending sleepAsync futures

Open
#889 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java, kotlin
Domain
api

Research direction

Start at DefaultSleeper.sleepAsync() and close(), then inspect how RetryingHttpClient composes its next request from the sleep future. Add regression coverage showing pending futures settle on close, completed sleeps leave pending tracking, repeated close is safe, and post-close sleepAsync() returns a settled future.

Written by the indexing model from the issue text.

Description

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.
Dominant language
Kotlin
Stars
1.5k
Forks
265
Avg merge
8h 18m
Merged PRs (30d)
142

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openai/openai-java

All issues in openai/openai-java

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.