Conversation
TileFetcher.download deferred closing the HTTP response body only after the status-code switch, so any non-200 response (404, 5xx, etc.) returned early without closing the body, leaking the underlying connection's file descriptor. Move the defer right after the request succeeds so the body is always closed. Add regression tests covering the 404 and 500 paths.
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.
While running go-staticmap as a library I noticed that descriptors were piling up, sometimes leading to resource exhaustion. It turned out that the tile fetcher doesn't close the http response body when the response is non-200 (e.g. a 404 or 500 response still has a body that needs closing). I moved
defer resp.Body.Close()up, so it runs regardless of status code, and added tests to verify it's being closed. I've been running the patched version for a couple of days and the descriptor count went down massively.Thanks for this great library!