fix: tolerate EPERM when unlinking broker teardown files - #650
Open
SomSamantray wants to merge 3 commits into
Open
fix: tolerate EPERM when unlinking broker teardown files#650SomSamantray wants to merge 3 commits into
SomSamantray wants to merge 3 commits into
Conversation
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.
Summary
Fixes #633, Fixes #626:
teardownBrokerSessionandclearBrokerSessioncan throw when unlinking broker files that another process holds open. On Windows, deleting a locked file fails withEPERM, and becauseensureBrokerSessioncalls teardown on its stale-broker replacement path with no try/catch, the failure propagated up to the caller and the background job was markedfailedbefore any Codex work began.The three unguarded
unlinkSynccalls are now wrapped in the same baretry { ... } catch { // Ignore ... }guard the other cleanup steps in the same function already use:teardownBrokerSession: pid-file unlink, log-file unlinkclearBrokerSession: broker state-file (broker.json) unlink — same unguarded pattern one call later on the same propagation path, so the same symptom class would otherwise persistTeardown remains best-effort: a failed unlink never prevents the remaining cleanup steps from running, and success-path behavior is unchanged.
Testing
tests/broker-lifecycle.test.mjswith 6 unit scenarios: happy path, EPERM on pid file (log still removed), EPERM on log file, missing files, remaining-cleanup integration, and EPERM on the broker state file. The four EPERM scenarios failed before the change (red) and pass after.npm test: 97/97 passing.npm run build(prebuild + tsc): clean.Note: the EPERM failure mode is simulated via an
fs.unlinkSyncpatch, so the test is platform-independent; a manual Windows re-run of the issue's repro is recommended to confirm the reported symptom is gone, but is not blocking.Security Disclosure
No security-relevant changes.
Agent Disclosure
This change was implemented with the assistance of an AI coding agent (opencode), reviewed and tested by the author before submission.