fix(encryption): detach a coalesced DEK load from its leader - #7
Merged
Merged
Conversation
DoChan ran the shared load on whichever caller arrived first. If that request was cancelled mid-load, every caller coalesced onto the same key ref got its context.Canceled, even though their own contexts were live. In waas that surfaces as sessions silently missing from a config reconcile, because the caller logs and skips a binding it cannot decrypt. The load now runs on a context carrying the leader's values but neither its cancellation nor its deadline, bounded by dekLoadTimeout so a load nothing is waiting for still terminates. Waiters keep leaving early on their own context. Two consequences of outliving the request, both handled here: migrateKey re-encrypts shares, which draws the AES-CBC IV from the NSM session; the leader's session is closed once its handler returns. It now opens its own attestation and no longer takes one from the caller. Span mutations are mutex-guarded but the middleware marshals the tree by reflection without the lock, so a still-running child would be read while it is written. tracing.Detach starts the load's span as a new root. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
patrislav
force-pushed
the
fix/detach-coalesced-dek-load
branch
from
September 25, 2026 11:21
ef3d43d to
217881f
Compare
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.
Follow-up to #4, from review on waas#132.
DoChanruns the shared load on whichever caller arrived first. Cancel that request mid-load — client disconnect, deadline — and every caller coalesced onto the same key ref gets itscontext.Canceled, despite their own contexts being live.Pool DEKs are shared across many rows, so a cold cache or an expired entry reliably produces concurrent misses on one key ref. In waas the failure is silent:
ListActiveSessionsskips a binding it cannot decrypt, andAdvanceConfigreconciles the on-chain session set to what came back — so an unrelated disconnect can drop live sessions from a wallet's config.Fix
The load keeps the leader's context values but neither its cancellation nor its deadline, bounded by
dekLoadTimeout(30s) so a load nothing waits for still terminates. That bound also covers the hung-load case from #4, which is why there is still noForget. Waiters are unchanged — they leave early on their own context.cancelis deferred inside the load goroutine: deferring it infetchDEKwould let a returning leader kill the load its waiters are blocked on.Two things follow from outliving the request:
migrateKeyopens its own attestation. Re-encrypting shares reachesaescbc.Encrypt(att, …), which draws the IV from the NSM session, and the middleware closes that session when the handler returns. Four mock expectations asserting migration used the caller's attestation had to be relaxed, which confirms it did.tracing.Detachroots the load's span.Spanlocks its mutations, but the middleware'sjson.Marshalreads the tree by reflection unlocked — safe only while every span is finished when the request ends.Test
TestPool_DecryptSurvivesLeaderCancellationholds the leader's share decrypt, cancels the leader, and asserts a follower on the same load still succeeds. Point the load back atctxand it fails.MockRemoteKey.Decryptnow observes cancellation; without that it ignoredctxand the test passed either way.🤖 Generated with Claude Code