Skip to content

_examples/exactly-once-counter: close HTTP response body and back off retries#675

Open
SAY-5 wants to merge 1 commit intoThreeDotsLabs:masterfrom
SAY-5:fix/exactly-once-counter-response-leak-664
Open

_examples/exactly-once-counter: close HTTP response body and back off retries#675
SAY-5 wants to merge 1 commit intoThreeDotsLabs:masterfrom
SAY-5:fix/exactly-once-counter-response-leak-664

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 21, 2026

Summary

sendCountRequest looped http.Post against localhost:8080 without ever closing resp.Body. Every request leaked a TCP connection and its background reader goroutine; under the example's 5000-message load that accumulated into fd exhaustion / goroutine deadlock. A non-204 status also retried in a tight hot loop.

Fix

  • Drain + Close resp.Body after every response so net/http can reuse the connection.
  • Sleep 100ms between retries (both on error and on non-204) to stop the CPU-spin.

Pure example-code change; no effect on the watermill library itself.

Fixes

Fixes #664

Signed-off-by: SAY-5 SAY-5@users.noreply.github.com

… retries

sendCountRequest looped http.Post against localhost:8080 without ever
closing resp.Body, so every request leaked a TCP connection and its
background reader goroutine; under the example's 5000-message load
that accumulated into fd exhaustion / goroutine deadlock. A non-204
status also retried in a tight hot loop.

Drain and Close resp.Body after every response so net/http can reuse
the connection, and sleep 100ms between retries (both on error and
on non-204) to stop the CPU-spin. Pure example code change, no effect
on the watermill library itself.

Fixes ThreeDotsLabs#664.

Signed-off-by: SAY-5 <SAY-5@users.noreply.github.com>
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