DefaultSleeper.close can strand pending sleepAsync futures
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
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
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from openai/openai-java
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
openai/openai-java#886 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
openai/openai-java#802 · 2 comments · 3 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
openai/openai-java#973 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
openai/openai-java#956 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
openai/openai-java#952 ·
Maintainers usually reply within 1 day
All issues in openai/openai-java
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
sqldelight/sqldelight#6382 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
521xueweihan/HelloGitHub#3846 ·
-
Bug Domain changed
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
keiyoushi/extensions-source#19624 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 1/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 5 days