Fix temp state dir leak and unchecked Close in terraform bind#5521
Open
simonfaltum wants to merge 2 commits into
Open
Fix temp state dir leak and unchecked Close in terraform bind#5521simonfaltum wants to merge 2 commits into
simonfaltum wants to merge 2 commits into
Conversation
Co-authored-by: Isaac
Contributor
Waiting for approvalBased on git history, these people are best suited to review:
Eligible reviewers: Suggestions based on git history. See OWNERS for ownership rules. |
Collaborator
|
Commit: cc230ab
22 interesting tests: 15 SKIP, 7 RECOVERED
Top 30 slowest tests (at least 2 minutes):
|
Co-authored-by: Isaac
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.
Why
Found during a full-repo review of the CLI.
bundle deployment bind(terraform engine) creates a temporary directory for the imported state, but the cleanupdeferis registered only afterterraform importandterraform plansucceed. Any failure in those steps leaves astate-*directory behind in the system temp dir on every retry. Separately, the state file written to the bundle cache directory is closed via a baredefer, so a failing flush on Close is ignored and the command can report success while leaving a truncated state file.Changes
Before, a failed import or plan leaked the temporary state directory and a failed Close on the written state file was silently ignored; now the temp dir is always removed and a Close failure fails the bind.
defer os.RemoveAll(tmpDir)immediately afteros.MkdirTempinbundle/deploy/terraform/import.go, so the temp dir is cleaned up on all paths, including import and plan errors.Closeon the written state file after the copy completes. The deferred Close stays in place for earlier error paths and is a no-op after the explicit one.Test plan
go test ./bundle/deploy/terraform/go test ./acceptance -run 'TestAccept/bundle/deployment/bind/job/noop-job'(terraform and direct variants; covers the bind happy path where the state file is written)go test ./acceptance -run 'TestAccept/bundle/deployment/bind/job/job-abort-bind'(terraform and direct variants; covers the error path after plan)./task fmt-q,./task lint-q, and./task checkspassThis pull request and its description were written by Isaac.