Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

DefaultSleeper.close can strand pending sleepAsync futures

Đang mở
#889 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
java, kotlin
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu từ DefaultSleeper.sleepAsync() và close(), sau đó kiểm tra cách RetryingHttpClient tạo request tiếp theo từ sleep future. Thêm kiểm thử hồi quy cho thấy các future đang chờ được hoàn tất khi đóng, các sleep đã hoàn tất không để lại việc theo dõi đang chờ, việc gọi close() lặp lại là an toàn và sleepAsync() trả về một future đã hoàn tất sau khi đóng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.
Ngôn ngữ chính
Kotlin
Star
1.5k
Fork
264
Merge trung bình
13 giờ 51 phút
Pull request đã merge (30 ngày)
113

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của openai/openai-java

Tất cả issue của openai/openai-java

Issue tương tự

Thêm issue về Kotlin

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.