Skip to content

fix: close resources on error paths - #7940

Merged
steadytao merged 2 commits into
caddyserver:masterfrom
ittakestwo123:fix/7833-close-resources
Aug 16, 2026
Merged

steadytao merged 2 commits into
caddyserver:masterfrom
ittakestwo123:fix/7833-close-resources

Conversation

@ittakestwo123

Copy link
Copy Markdown
Contributor

Summary

Fix all four resource leaks reported in #7833:

  • Close reverse proxy connections on PROXY protocol error paths.
  • Close resp.Body for failed package-download responses.
  • Close log files on file-writer error paths when roll is disabled.
  • Close temporary configuration files used by 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 ./caddytest

Assistance 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.

Copilot AI lite review requested due to automatic review settings August 15, 2026 07:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.Conn is closed on reverse proxy dial error paths when PROXY protocol setup fails, while preserving successful connections.
  • Close resp.Body when downloadBuild() receives HTTP error responses; add a regression test to verify closure.
  • Ensure opened log files and caddytest temp 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.

@CLAassistant

CLAassistant commented Aug 15, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Correct. LGTM. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🐞 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants