Repository navigation
fix: close resources on error paths - #7940
Merged
steadytao merged 2 commits intoAug 16, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes four resource-leak error paths reported in #7833 across reverse proxy dialing (PROXY protocol), package download error handling, log file opening, and caddytest temp config handling—improving reliability and avoiding leaked FDs/connections.
Changes:
- Ensure
net.Connis closed on reverse proxy dial error paths when PROXY protocol setup fails, while preserving successful connections. - Close
resp.BodywhendownloadBuild()receives HTTP error responses; add a regression test to verify closure. - Ensure opened log files and
caddytesttemp config files are closed on relevant error/cleanup paths.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| modules/logging/filewriter.go | Adds deferred close logic to ensure files are closed on error paths, while avoiding double-close on successful returns/rolling mode. |
| modules/caddyhttp/reverseproxy/httptransport.go | Closes dialed connections on PROXY protocol error returns via a guarded defer; keeps connection open on success. |
| modules/caddyhttp/reverseproxy/httptransport_test.go | Adds a regression test verifying reverse-proxy dial closes connections on PROXY protocol validation failures. |
| cmd/packagesfuncs.go | Closes error-response bodies for failed downloads to prevent leaking HTTP response resources. |
| cmd/packagesfuncs_test.go | Adds a regression test ensuring downloadBuild() closes resp.Body when returning an HTTP error. |
| caddytest/caddytest.go | Closes temp config file handles in test cleanup and on write failure to avoid leaked descriptors during integration tests. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This was referenced Aug 16, 2026
This was referenced Sep 30, 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.
Summary
Fix all four resource leaks reported in #7833:
resp.Bodyfor failed package-download responses.rollis disabled.caddytest.Regression tests were added for the reverse proxy connection and HTTP response-body cleanup.
Tests
go test -race -short ./...go build ./...go vet ./modules/caddyhttp/reverseproxy ./modules/logging ./cmd ./caddytestAssistance Disclosure
OpenAI Codex was used to inspect issue #7833, implement the fixes, and write regression tests. The changes and test results were reviewed by myself.