Fix file descriptor leak in pipe-bootstrap on error paths#23623
Fix file descriptor leak in pipe-bootstrap on error paths#23623vigneshakaviki wants to merge 1 commit into
Conversation
The Run function opened a file descriptor via os.OpenFile but failed to close it on error paths (lines 62 and 67 in the original code). This caused file descriptor leaks when either the open() call or buf.WriteTo() call failed. Fixed by adding defer f.Close() immediately after successful file opening, ensuring the descriptor is closed in all code paths including errors. Fixes: hashicorp#23256
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Test User seems not to be a GitHub user. Have you signed the CLA already but the status is still pending? Recheck it. |
1 similar comment
|
Thank you for your submission! We require that all contributors sign our Contributor License Agreement ("CLA") before we can accept the contribution. Read and sign the agreement Learn more about why HashiCorp requires a CLA and what the CLA includes Test User seems not to be a GitHub user. Have you signed the CLA already but the status is still pending? Recheck it. |
Summary
Fixes a file descriptor leak in the
pipe-bootstrapcommand where file descriptors were not closed on error paths.Fixes #23256
Problem
The
Run()function incommand/connect/envoy/pipe-bootstrap/connect_envoy_pipe-bootstrap.goopened a file descriptor viaos.OpenFile()but failed to close it when either:os.OpenFile()call returned an error (line 62)buf.WriteTo(f)call returned an error (line 67)This caused file descriptor leaks under error conditions, which can lead to resource exhaustion and process instability.
Solution
Added
defer f.Close()immediately after successful file opening, ensuring the descriptor is closed in all code paths including error cases.Changes
defer f.Close()after successfulos.OpenFile()callTesting
Impact
Risk: Minimal - single line addition with no logic changes
Benefit: Prevents file descriptor exhaustion during bootstrap failures
Scope: Internal Envoy bootstrap mechanism only