Skip to content

fix: close leaked file handles in pull_test.go HTTP handlers#4657

Merged
brandtkeller merged 2 commits into
zarf-dev:mainfrom
joonas:fix/close-leaked-file-handles-in-pull-test
Mar 4, 2026
Merged

fix: close leaked file handles in pull_test.go HTTP handlers#4657
brandtkeller merged 2 commits into
zarf-dev:mainfrom
joonas:fix/close-leaked-file-handles-in-pull-test

Conversation

@joonas
Copy link
Copy Markdown
Contributor

@joonas joonas commented Feb 28, 2026

Description

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.

Checklist before merging

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]>
@joonas joonas requested review from a team as code owners February 28, 2026 18:34
@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 28, 2026

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit 15d7564
🔍 Latest deploy log https://app.netlify.com/projects/zarf-docs/deploys/69a389c44fd0ad00083bc6f5

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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]>
Copy link
Copy Markdown
Member

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@joonas
Copy link
Copy Markdown
Contributor Author

joonas commented Mar 2, 2026

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.

Yeah, I initially used require.NoError inside an anonymous function block for the defer, but that felt unnecessary given the context these are for.

@brandtkeller brandtkeller added this pull request to the merge queue Mar 4, 2026
Merged via the queue into zarf-dev:main with commit 0ef41d7 Mar 4, 2026
35 of 36 checks passed
@github-project-automation github-project-automation Bot moved this to Done in Zarf Mar 4, 2026
@joonas joonas deleted the fix/close-leaked-file-handles-in-pull-test branch March 4, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants