anthropics / anthropics/anthropic-sdk-go
requestconfig: prevent per-attempt timeout timer leaks during retries
- Ngôn ngữ chính
- Go
- Star
- 1.2k
- Fork
- 213
- Merge trung bình
- 1 ngày 12 giờ
- Pull request đã merge (30 ngày)
- 11
Mô tả
## Environment
**Go SDK**: v1.62.0
## Bug
RequestConfig.Execute creates a timeout for each retry attempt.
The problem is that when we retry, the timeout from the previous attempt is not cancelled. The cancel variable gets replaced with the new attempt's cancel function.
There is also a defer inside the loop, but all the deferred functions use the same cancel variable. When the function finishes, they all end up calling the cancel function from the last attempt.
This means the earlier timers are never cancelled and stay alive until their timeout expires.
For example, with 4 attempts:
```
Attempt 1 → timer A
Attempt 2 → timer B
Attempt 3 → timer C
Attempt 4 → timer D
```
```
Execute returns → D is cancelled
A, B, C remain alive
```
## Impact
With the default `MaxRetries=2`, a request that uses all its retries can leave 2 timers running unnecessarily.
**The requests still work as expected.** But if there are lots of retries, especially from 429 or 5xx responses, these timers can build up and use extra memory and runtime resources.
## Expected vs actual
**Expected:**
- Cancel the current timeout before starting the next retry.
- Cancel the final timeout when Execute returns.
**Actual:**
- The previous timeout is never cancelled.
- Only the last timeout gets cancelled.
- Earlier timers stay alive until they expire.
## Suggested fix
Cancel the previous timeout at the start of each retry and keep one defer outside the loop for the final timeout.
Hướng dẫn đóng góp
Hướng nghiên cứu
Start at RequestConfig.Execute and trace how the timeout and cancel function are created for each retry attempt. Verify the retry flow and existing tests, then confirm that each prior attempt's timeout is cancelled before the next attempt and that the final timeout is cancelled when Execute returns.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- go
- Lĩnh vực
- api
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 74/100