Skip to content

caddytest: close temp config file handle in validateTestPrerequisites#7839

Open
vvdvortsova wants to merge 1 commit into
caddyserver:masterfrom
vvdvortsova:fix-7833-4-add-close
Open

caddytest: close temp config file handle in validateTestPrerequisites#7839
vvdvortsova wants to merge 1 commit into
caddyserver:masterfrom
vvdvortsova:fix-7833-4-add-close

Conversation

@vvdvortsova

Copy link
Copy Markdown

I'm not a native English speaker, so I used AI to help translate this PR description. The code and analysis are my own.

What

Fix resource leak in validateTestPrerequisites.
Fix for issue #7833.

validateTestPrerequisites in caddytest/caddytest.go created a temp file via os.CreateTemp and only removed it from disk in t.Cleanup (os.Remove(f.Name())), never closing the file descriptor including on the early return err if writing the config failed. Added defer f.Close() right after the file is created.

Testing
go build ./caddytest/...
go vet ./caddytest/...

@CLAassistant

CLAassistant commented Jun 23, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@steadytao

Copy link
Copy Markdown
Member

This should close the temp file before starting Caddy from it. With the current defer, the handle stays open until ValidateTestPrerequisites returns so Caddy may still read the config while the writer handle is open. Closing immediately after the fmt.Fprintf succeeds would be cleaner. We also need a signed CLA and an AI assistance disclosure, please.

@vvdvortsova
vvdvortsova force-pushed the fix-7833-4-add-close branch from 6872e99 to 9c3bedf Compare June 29, 2026 09:10
@vvdvortsova

Copy link
Copy Markdown
Author

This should close the temp file before starting Caddy from it. With the current defer, the handle stays open until ValidateTestPrerequisites returns so Caddy may still read the config while the writer handle is open. Closing immediately after the fmt.Fprintf succeeds would be cleaner. We also need a signed CLA and an AI assistance disclosure, please.

I added signed CLA and added f.Close() after fmt.Fprintf call. I used AI assistance (Claude) to write this PR. I'm not a native English speaker.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants