fix: race condition in keymanager API#1150
Merged
usmansaleem merged 1 commit intoConsensys:masterfrom Jan 15, 2026
Merged
Conversation
...rotection/src/main/java/tech/pegasys/web3signer/slashingprotection/RegisteredValidators.java
Show resolved
Hide resolved
3724add to
004a4c2
Compare
004a4c2 to
134288c
Compare
usmansaleem
reviewed
Jan 13, 2026
The BiMap used to have a map of public key to db indexes is not properly synchronized: it can effectively be accessed from multiple threads in parallel: - in read-only from signing requests from validator clients (1), - in a writable-way from the key manager API (2). When mixing the keymanager API with signatures at the same time, this sometimes causes memory corruption leading to IllegalStateException stacktraces (Unregistered validator), making a subset of loaded keys unavailable until restart. This PR ensures the BiMap is synchronized, this implies some potential contention especially around (1) which is why it's using a readwrite lock approach. This was tested at scale both on Hoodi and Mainnet for multiple days without issues.
134288c to
fab6259
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
PR Description
The BiMap used to have a map of public key to db indexes is not properly synchronized: it can effectively be accessed from multiple threads in parallel:
When mixing the keymanager API with signatures at the same time, this sometimes causes corruption leading to stacktraces when trying to sign with a bogus subset of keys that are loaded, making them unavailable until restart.
This PR ensures the BiMap is synchronized, this implies some potential contention especially around (1) which is why it's using a readwrite lock approach. This was tested at scale both on Hoodi and Mainnet for multiple days without issues.
Fixed Issue(s)
Changelog
Testing
Note
Improves thread safety of the in-memory validator registry to prevent sporadic
IllegalStateExceptionwhen key manager operations run alongside signing.RegisteredValidatorsBiMapaccess with aReadWriteLock(ReentrantReadWriteLock) for reads (validatorIds,getPublicKeyForValidatorId,getValidatorIdForPublicKey) and writes (registerValidators)Set.copyOf(...)instead of exposing live viewsCHANGELOG.mdunder Upcoming Release: bug fix entry for unregistered validator race in keymanager APIWritten by Cursor Bugbot for commit fab6259. This will update automatically on new commits. Configure here.