fix: close leaked file handles in pull_test.go HTTP handlers#4657
Merged
brandtkeller merged 2 commits intoMar 4, 2026
Merged
Conversation
The test HTTP handlers in `TestPull`, `TestPullUncompressed`, and `TestPullUnsupported` each call `os.Open` to serve a package file but never close the resulting handle. The file descriptor leaks for the lifetime of the test process — one per request to the `httptest.Server`. Add `defer file.Close()` after the open-error check in all three handlers. Since each handler invocation is its own function call, the `defer` fires at exactly the right time — when the handler returns after `io.Copy` completes. Signed-off-by: Joonas Bergius <[email protected]>
✅ Deploy Preview for zarf-docs canceled.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 🚀 New features to boost your workflow:
|
The `errcheck` linter with `check-blank: true` flagged three `defer file.Close()` calls in `pull_test.go` HTTP handler closures. These are best-effort cleanup in test fixtures where a close error is not actionable, so add `//nolint:errcheck` directives rather than introducing error-handling ceremony. Signed-off-by: Joonas Bergius <[email protected]>
AustinAbro321
approved these changes
Mar 2, 2026
Member
AustinAbro321
left a comment
There was a problem hiding this comment.
LGTM, was curious if it'd make sense to check the error here, but these test servers run as gorountines so we don't want to use require.NoError in them, and I don't think it's worth passing a errors through a channel to check.
Contributor
Author
Yeah, I initially used |
brandtkeller
approved these changes
Mar 4, 2026
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.
Description
The test HTTP handlers in
TestPull,TestPullUncompressed, andTestPullUnsupportedeach callos.Opento serve a package file but never close the resulting handle. The file descriptor leaks for the lifetime of the test process — one per request to thehttptest.Server.Add
defer file.Close()after the open-error check in all three handlers. Since each handler invocation is its own function call, thedeferfires at exactly the right time — when the handler returns afterio.Copycompletes.Checklist before merging