Skip to content

fix: reset request body for retry attempts#275

Open
joshedney wants to merge 4 commits intonextfrom
je/plat-15955
Open

fix: reset request body for retry attempts#275
joshedney wants to merge 4 commits intonextfrom
je/plat-15955

Conversation

@joshedney
Copy link
Contributor

@joshedney joshedney commented Mar 25, 2026

Goal

Fix HTTP request retry failures that occurred when upload requests needed to be retried. When retries were enabled (--retries > 0), subsequent retry attempts would fail with the error: error sending request: Post "https://upload.bugsnag.com:443/ndk-symbol": http: ContentLength=1278529 with Body length 0

This prevented users from successfully uploading symbol files when transient network issues or duplicate file conflicts occurred.

Design

The root cause was that HTTP request bodies (io.Reader) can only be read once. When a request failed and needed to be retried, the body stream had already been consumed by the first attempt, leaving an empty body for subsequent retries.

The fix implements the following approach:

  1. Store body bytes upfront: Before creating the HTTP request, capture the complete body content as a byte slice
  2. Use seekable readers: Replace bytes.Buffer with bytes.NewReader, which can be recreated from the stored bytes
  3. Implement GetBody: Set the http.Request.GetBody field to provide a function that returns a fresh reader from the stored bytes
  4. Explicitly reset body on retry: In the retry loop, call GetBody() and assign the result to request.Body before each retry attempt

This approach allows the request body to be "rewound" and re-read for each retry attempt, which is the standard pattern for implementing retryable HTTP requests in Go.

Changeset

  • pkg/server/request.go:
    • Modified buildFileRequest(): Store multipart form body as bytes, use bytes.NewReader, and set GetBody callback
    • Modified ProcessBuildRequest(): Store JSON payload bytes, use bytes.NewReader, and set GetBody callback
    • Modified processRequest(): Added explicit body reset logic before each retry by calling GetBody() and reassigning to request.Body

Testing

Manual Testing:

  • Tested with the command: ./bin/arm64-macos-bugsnag-cli upload unity-android platforms-examples/Unity/UnityExample-1.0-v1-IL2CPP.symbols.zip --api-key=<key> --retries=3 --verbose
  • Verified that retries now successfully re-send the request body instead of failing with "Body length 0" errors
  • Confirmed that the fix compiles successfully with make build

Automated Testing:
Covered by CI

@joshedney joshedney requested a review from tomlongridge March 25, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant