fix: Lock while generating the Security Key#73
Merged
brunobritodev merged 4 commits intoJul 16, 2026
Merged
Conversation
brunobritodev
marked this pull request as ready for review
July 16, 2026 15:11
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.
Fixes duplicate key generation when a scoped JwtService rotates keys concurrently across requests #65
Fixes duplicate key generation when a scoped JwtService rotates keys concurrently across replicas
Issue: When run on multiple pods (Kubernetes), the pods independently generate new keys and cache the last two keys. On a cluster with 3 replicas with
AlgorithmsToKeep = 2, all three generate new keys and cache different pairs of keys.Fix: Use the previous valid key's Id, and increment it, and use that to generate the GUID of the new key - Every instance generates the same GUID and tries to insert, the database fails one of the inserts acting as the coordinator.
Cross-replica coordination only works on EF Core store - Database is used as the coordinator when multiple replicas race.
EF Core store: computes a deterministic Id from SHA256(
use:kty:version) so concurrent inserts collide on the primary key. On collision/transient fault it detaches its own entity, re-reads the winner, and returns it (throws only if no winner exists).InMemoryStore,DataProtectionStore,FileSystemStoreupdated to the new signatures.Changed caching from Sliding to Absolute. When a key is revoked, the key gets refreshed after the cache expires instead of renewing the stale cache.