Repository navigation
[sentry:7850959954] A shutdown that lands while createAtomicCore is still finishing releases the instance lock (closing its FileHandle); startup then reaches `await lock.publish(control.ho - #118
Merged
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.
A shutdown that lands while
createAtomicCoreis still finishing releases the instance lock (closing its FileHandle); startup then reachesawait lock.publish(control.host, control.port)on the way out, andwriteRecord'shandle.truncate(0)throws EBADF ("file closed"). The throw escapes createAtomicCore into app-daemon.ts's startup catch, where the code table cannot classify EBADF, so the report becomes the genericcore startup: unknownat fatal level. The fix marks the lock released inrelease()before the descriptor is closed, and makespublish()skip the write once released: a released lock has no record to announce, the file is gone and may belong to a new owner. The escaped await then resolves and the already-decided shutdown completes normally. Acquire, the ready-record contract for live owners, and the persisted record format are unchanged; the regression test asserts exactly that pair of behaviours.Evidence:
Event stack: runAppDaemon -> src/core/create.ts:1613 createAtomicCore -> src/lock/instance-lock.ts:232 publish -> src/lock/instance-lock.ts:246 writeRecord -> node:fs/promises truncate -> throwEBADFIfNecessary; event facts win32/x64, host atomic-chat, owner_scope app, component core, operation startup.
src/lock/instance-lock.ts:
writeRecordstarts withawait handle.truncate(0);InstanceLock.release()was the only closer of that handle (await this.handle.close()), so the EBADF proves release ran before publish.acquire's own
writeRecordhad already succeeded on the same handle, so the descriptor was valid at lock time and died between the two writes.The only in-process shutdown that can run while create() is in flight is the app-lease interval in src/core/create.ts (startupDeadline = arming + CLIENT_EXPIRY_MS, everRegistered false, no work => 'retire' => void core.shutdown() => await this.lock.release()); create.ts publishes only after reapOrphans, container resolve, recover() of managed/FastFlowLM operations, startupCleanup and tunnel reaps.
Pre-fix probe (saved plan):
await lock.release(); await lock.publish('[redacted]', 42424)rejected withError: file closed; control case on a never-released lock resolved.After the patch,
src/lock/instance-lock-publish.test.tspasses both cases: publish after release resolves and leaves the lock state{ kind: 'free' }; publish on a live lock yields{ kind: 'owned', record: { state: 'ready' } }(2/2 passed).Release dist c21d779 vs base a66aad0 differs only in diffusion args/compat, a CLI race test, a runtime cleanup retry and version.ts; src/lock/ and src/core/create.ts are byte-identical to base, so the defect is present in the release and unrepaired in main.
Patch delta is two behaviours: a
releasedflag set at the top of release() beforehandle.close(), and an early return in publish() while that flag is set.Regression tests: src/lock/instance-lock-publish.test.ts
Full CI and human review are required.
Report: http://127.0.0.1:8080/tenants/707d0855-80ab-4e1f-a156-f1c4546cbf52/runs/b115d7d6-4c15-43ba-8ca6-cfe21461bb30
Sentry: https://atomic-chat.sentry.io/issues/7850959954/