fix(gateway-lock): close fd when writeFile fails after acquiring lock#98848
fix(gateway-lock): close fd when writeFile fails after acquiring lock#98848zhangLei99586 wants to merge 3 commits into
Conversation
When fs.open(lockPath, 'wx') succeeded but writeFile() failed (e.g. disk full), the code threw without closing the file handle, leaking a file descriptor. Wrap the write in an inner try-catch that closes the handle and removes the partial lock file.
|
Codex review: needs real behavior proof before merge. Reviewed July 3, 2026, 2:37 AM ET / 06:37 UTC. Summary PR surface: Source +8, Tests +23. Total +31 across 2 files. Reproducibility: yes. Source-level reproduction is high confidence: make Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land this narrow Do we have a high-confidence way to reproduce the issue? Yes. Source-level reproduction is high confidence: make Is this the best way to solve the issue? Yes for the code shape: cleanup belongs inside AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against c785196287d0. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +8, Tests +23. Total +31 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
Prove that when fs.open succeeds but writeFile rejects (e.g. disk full), the handle is closed and the partial lock file is removed before throwing GatewayLockError. This covers the distinct path not tested by the existing EACCES-on-open-only case.
301d5a4 to
366a50c
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
The test previously hardcoded lockPath as gateway.lock, but the actual lock path uses SHA256 hash. Use resolveLockPath(env).lockPath so the cleanup assertion matches the real acquireGatewayLock behavior.
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
Superseded by #99291, which landed as The landed fix keeps cleanup inside |
Related: #98958
What Problem This Solves
fs.open(lockPath, 'wx')acquired the lock but ifwriteFile()failed (disk full, etc), the code threw without closing the handle or removing the partial lock file, leaking an fd.Why This Change Was Made
Inner try-catch closes the handle (
handle.close()) and removes the partial lock file (fs.rm) before re-throwingGatewayLockError.User Impact
No user-visible change. Prevents fd leak on disk errors during gateway lock acquisition.
Evidence
Failure-injection regression test with hashed lock path:
src/plugin-sdk/file-lock.test.ts:158