Rate-limit retry replays a consumed request body for POST/PUT/PATCH
Maintainer thường phản hồi trong vòng 1 ngày
@AdamMagued đang làm issue này rồi.
Từ ngày 21/10/2026.
Đá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
- 70/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Start with the retry branch in github/github.go at lines 1521–1529, then read NewRequest and the existing retry tests in github/github_test.go named in the issue. Add regression coverage for POST, PUT, and PATCH bodies and for a non-replayable body. Done means retry requests preserve replayable bodies and requests without a replayable body are not retried.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Summary
The automatic primary rate-limit retry path in Client.bareDo re-sends a cloned *http.Request without restoring its body. For any request that carries a body (POST, PUT, PATCH), the original req.Body has already been consumed by the first caller.Do(req) call, so the retry sends an empty body or fails on ContentLength.
Location
github/github.go:1521-1529 (retry branch in bareDo), with request construction at github/github.go:993-1037 (NewRequest) and the send at github/github.go:1464 (caller.Do(req)).
var rateLimitError *RateLimitError
if errors.As(err, &rateLimitError) &&
ctx.Value(SleepUntilPrimaryRateLimitResetWhenRateLimited) != nil {
if err := sleepUntilResetWithBuffer(ctx, rateLimitError.Rate.Reset.Time); err != nil {
return response, err
}
// retry the request now the rate limit should have been reset
newReq := req.Clone(context.WithValue(ctx, SleepUntilPrimaryRateLimitResetWhenRateLimited, nil))
return c.bareDo(caller, newReq)
}
Details
NewRequest encodes the body into a *bytes.Buffer:
var buf io.ReadWriter
if body != nil {
buf = &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetEscapeHTML(false)
err := enc.Encode(body)
if err != nil {
return nil, err
}
}
req, err := http.NewRequestWithContext(ctx, method, u.String(), buf)
For the *bytes.Buffer case, net/http.NewRequestWithContext populates req.GetBody and sets req.ContentLength. However, bareDo never uses GetBody. It calls caller.Do(req) at line 1464, which reads req.Body to EOF (and closes it). When a *RateLimitError triggers the retry branch, req.Clone(...) performs a shallow copy: the cloned request keeps the same consumed *http.Request.Body reader and the original ContentLength. The retry therefore either sends a zero-length body while still advertising the original ContentLength, or returns an error such as http: ContentLength=N with Body length 0.
The fix belongs in this retry path (or in bareDo before every send): call req.GetBody() and assign the resulting reader to req.Body before re-sending. If GetBody is nil (a body that cannot be replayed, for example a stream passed to NewFormRequest), the retry must not be attempted, because there is no way to reconstruct the payload.
Impact
- Users who opt into
SleepUntilPrimaryRateLimitResetWhenRateLimitedand then perform a write operation (POST/PUT/PATCH) can have that write silently truncated to an empty body after a primary rate-limit retry. This is a correctness issue and can cause confusing API errors or, depending on the endpoint, unintended empty updates. - The retry can also fail outright with a
ContentLengthmismatch error instead of succeeding on the second attempt. - GET requests are unaffected, which is why existing tests do not detect this.
Suggested fix
In the retry branch, restore the body from GetBody before cloning or re-sending:
newReq := req.Clone(context.WithValue(ctx, SleepUntilPrimaryRateLimitResetWhenRateLimited, nil))
if req.GetBody != nil {
body, err := req.GetBody()
if err != nil {
return response, err
}
newReq.Body = body
} else if req.Body != nil && req.Body != http.NoBody {
// Body cannot be replayed; do not retry.
return response, err
}
return c.bareDo(caller, newReq)
Applying the restore inside bareDo before each caller.Do would also protect other re-send paths, but the minimal change is the rate-limit retry branch.
Verification
- Static review of
github/github.goat HEAD2190e6a(2026-10-22):NewRequestencodes intobytes.Buffer,bareDocallscaller.Doonce and thenreq.Cloneon retry, and noGetBodyrestoration exists ingithub/github.go. - Existing retry coverage is GET-only. The
SleepUntilPrimaryRateLimitResetWhenRateLimitedtests ingithub/github_test.go(lines 3033, 3066, 3095, 3150, 3201) all construct requests with"GET"andnilbody, so they never exercise body replay. - Suggested regression tests: a table test using POST, PUT, and PATCH where the handler returns a
*RateLimitError(403 with rate-limit headers) on the first call and200on the second, asserting the second request receives the original JSON body. Add a case for a non-replayable body to assert the retry is skipped. - This report is based on static source review. No runtime proof of concept was executed.
- Ngôn ngữ chính
- Go
- Star
- 11.3k
- Fork
- 2.6k
- Merge trung bình
- 2 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 38
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của google/go-github
-
otel: redact sensitive query parameters before recording http.urlCó thể đã có người làm @sai5880 đã nhận 1 ngày trước. Đang mở
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Error() methods modify the request URL of the response they wrapCó thể đã có người làm @AdamMagued đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 30/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Discuss the future of this repoĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 5/100
google/go-github#4636 · 11 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
http.Client.Timeout is ignored by redirect-aware requestsCó thể đã có người làm @sb123sb123 đã nhận 31 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Add Copilot content exclusion set/get enterprise and org set endpointsCó thể đã có người làm @Tens1des đã nhận 45 ngày trước. Đang mở
google/go-github#4526 · 1 bình luận · 1 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của google/go-github
Issue tương tự
-
confirmed enhancement go
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
DennisVlaanderen/aerendil#154 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Generated README and SKILL omit HTTP-transport security settings and what local data the CLI keepsĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
mvanhorn/cli-printing-press#5181 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 83/100
Adyen/agent-marketplace#922 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
filer.remote.sync writes the S3 bucket-owner index (<buckets>/.system/owners/...) to remote storageĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày