You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resource leaks: unclosed file handles in workspace_new, file provisioner, login, and local-exec #38575
This is an internal code issue. The resource leaks affect four different code paths, each triggered by normal Terraform operations:
terraform workspace new -state=FILE (leaks file handle)
file provisioner (leaks temp file handle per invocation)
terraform login (leaks HTTP response body on read error)
local-exec provisioner (leaks pipe read-end file descriptor per invocation)
# Example triggering leak #2 and #4:resource"null_resource""example" {
provisioner"file" {
source="local-file.txt"destination="/tmp/remote-file.txt"
}
provisioner"local-exec" {
command="echo hello"
}
}
Debug Output
No debug output; these are file descriptor leaks visible by code inspection. Long-running Terraform processes (e.g., applying many resources with provisioners) will accumulate leaked file descriptors.
Expected Behavior
All opened file handles, HTTP response bodies, and pipe file descriptors should be properly closed on all code paths, including error paths.
Actual Behavior
Four resource leaks across different packages:
internal/command/workspace_new.go: os.Open for reading existing state is never closed
internal/builtin/provisioners/file/resource_provisioner.go: ioutil.TempFile handle in getSrc() is never closed; the caller re-opens by path, so the original handle leaks
internal/command/login.go: defer resp.Body.Close() is placed after ioutil.ReadAll(resp.Body), meaning the body leaks if ReadAll returns an error (early return)
internal/builtin/provisioners/local-exec/resource_provisioner.go: os.Pipe() creates two file descriptors; the write end (pw) is closed, but the read end (pr) is never closed
Steps to Reproduce
Review the four files listed above
For each, trace the lifecycle of the opened resource (file handle, response body, pipe FD)
Note the missing Close() calls on error/completion paths
Additional Context
Each fix is minimal (adding defer f.Close(), moving a defer, adding pr.Close()). I intend to submit a fix for this issue and have a working implementation on my fork.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Activity
crw commentedon May 13, 2026
Thanks.
github-actions commentedon Jun 14, 2026
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.