Skip to content

fix(example): close HTTP response body and add retry backoff#672

Open
Yanhu007 wants to merge 1 commit intoThreeDotsLabs:masterfrom
Yanhu007:fix/example-response-body-leak
Open

fix(example): close HTTP response body and add retry backoff#672
Yanhu007 wants to merge 1 commit intoThreeDotsLabs:masterfrom
Yanhu007:fix/example-response-body-leak

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #664

Problem

sendCountRequest in the exactly-once-delivery-counter example:

  1. Never closes resp.Body — leaks file descriptors and TCP connections under load
  2. No retry backoff — retries immediately in a tight loop on error or non-204 status

Fix

  • Close resp.Body after reading the status code
  • Add 100ms sleep between retries

The sendCountRequest function in the exactly-once-delivery-counter
example has two issues:

1. resp.Body is never closed, leaking file descriptors and TCP
   connections under load.
2. On error or non-204 status, the function retries immediately
   in a tight loop with no backoff, potentially overwhelming
   the server.

Close the response body after reading the status code and add
a 100ms sleep between retries.

Fixes ThreeDotsLabs#664
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.

run.go: HTTP response body leak and potential goroutine deadlock

1 participant