_examples/exactly-once-counter: close HTTP response body and back off retries#675
Open
SAY-5 wants to merge 1 commit intoThreeDotsLabs:masterfrom
Open
_examples/exactly-once-counter: close HTTP response body and back off retries#675SAY-5 wants to merge 1 commit intoThreeDotsLabs:masterfrom
SAY-5 wants to merge 1 commit intoThreeDotsLabs:masterfrom
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sendCountRequestloopedhttp.Postagainstlocalhost:8080without ever closingresp.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
resp.Bodyafter every response sonet/httpcan reuse the connection.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