fix: close modsdir snapshot file descriptors#38311
fix: close modsdir snapshot file descriptors#38311buley wants to merge 2 commits intohashicorp:mainfrom
Conversation
|
Hi @buley, thanks for this submission. We typically will only review PRs after a submission is solicited and a solution is discussed with the maintainers in an issue, and for that reason I suspect we will close this PR. However, I will bring this to triage to see how we want to proceed. You can read more in https://github.com/hashicorp/terraform/blob/main/.github/CONTRIBUTING.md. Thanks again. |
| } | ||
|
|
||
| after := countOpenFileDescriptors(t) | ||
| if leaked := after - before; leaked > 2 { |
There was a problem hiding this comment.
Why are 2 file descriptors expected to leak?
There was a problem hiding this comment.
Appreciate your question, @DanielMSchmidt. The 2 isn't an expected leak count: it's a small tolerance margin to keep the test from being flaky due to unrelated runtime activity. The Go runtime, the test harness, and the logging subsystem may transiently open or close a file descriptor between the before and after snapshots, so a strict leaked > 0 check could produce false positives.
The test writes 32 iterations specifically so that a real leak is unambiguous: without the fix all 32 descriptors leak, which is well above the threshold. With the fix, the count stays at or near zero. So the invariant is really "no meaningful growth" rather than "exactly zero," with 2 as a conservative noise floor.
I could tighten this or use a different approach if you'd prefer — for example, I could check that leaked < iterations with a comment explaining the margin, or switch to a percentage-based threshold.
|
Hi @buley, we have recently updated our Contributing.md guidelines, if you are using an LLM in any manner as part of this contribution, we now require you to disclose this information. Can you confirm this is or is not employing LLM-assisted coding tools? Thanks! |
Fixes #38302
WriteSnapshotToDircreated the manifest file and returned after writing without closing it. This change closes the file on all paths, preserves close errors witherrors.Join, adds a regression test that fails if repeated writes leak descriptors, and includes the required changelog entry for the v1.16 release line.Target Release
1.16.x
Rollback Plan
Changes to Security Controls
No changes to security controls.
CHANGELOG entry