Three review findings on the original broker code, all confirmed real:
- registerConnection ran entirely outside withInstanceLock while
createEnrollment and revokeInstance hold it, and every step between
authentication and the credential write is a suspension point. A
handshake parked at the write could re-create a credential that
createEnrollment had just superseded, or connections.accept could
install a live socket for an instance revokeInstance had just torn
down (generation fencing does not help — accept installs at a higher
generation). Authentication now runs unlocked (a junk credential never
queues on the lock), then the whole mutation section — token consume,
credential persist, accept, ping fork, status publish — runs under
the instance lock with a fresh re-read, so a competing enrollment or
revocation that won the lock is fully visible and the handshake
rejects. teardownConnection takes no lock and only ever targets the
displaced socket, so the locked region cannot deadlock with it.
- RequestCorrelator ran input.send outside restore and outside the
timeout: a wedged transport write was unkillable and the response
timeout did not start until the write returned. Worse than reported:
in effect 4.0.0-beta.102, Effect.timeout applied OUTSIDE restore
inherits the surrounding uninterruptible region, so even the bare
await was un-interruptible. Send and await now both live inside
restore with the timeout inside it too; registration stays
uninterruptible so a response racing the write always finds its entry,
and ensuring releases on every exit.
Race tests park the handshake at a gated secret-store write and drive
the competing operation to completion; falsification runs confirm each
test fails against the unfixed code.
Co-Authored-By: Claude Fable 5 <[email protected]>