[#816] Unmap only the locked domainMap in FileChangelogDB.removeDomain() - #827
Merged
vharseko merged 1 commit intoAug 4, 2026
Conversation
…ngelogDB.removeDomain() removeDomain() reassigned the local variable whose monitor it was holding: a racing shutdownDB() drain, clearDB() or concurrent removeDomain() made domainToReplicaDBs.remove(baseDN) return null and the next line threw NullPointerException instead of the ChangelogException callers handle. Remove the entry only while it still maps the instance the monitor was taken on, and keep iterating that instance: replica DBs a concurrent remover already visited are cleared and shut down again harmlessly, and a domainMap recreated for the same baseDN is left untouched.
maximthomas
approved these changes
Aug 3, 2026
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 #816.
FileChangelogDB.removeDomain()reassigned the local variable whose monitor it was holding: a racingshutdownDB()drain,clearDB()or a concurrentremoveDomain()madedomainToReplicaDBs.remove(baseDN)returnnull, and the next line threwNullPointerExceptioninstead of theChangelogExceptioncallers such asReplicationServerDomain.clearDbs()handle.The entry is now removed only while it still maps the instance the monitor was taken on (an identity check under that monitor, which is what makes the check-then-remove atomic: every remover takes the same monitor before unmapping), and iteration stays on that instance:
Log.clear()returns at once on a closed log andFileReplicaDB.shutdown()is CAS-guarded;getOrCreateReplicaDB()is left untouched instead of being unmapped while holding the wrong monitor.The new
FileChangelogDBTestreproduces both windows deterministically: it holds the domainMap monitor, waits viaThreadMXBeanuntilremoveDomain()blocks on exactly that monitor, and simulates the concurrent remover inside the window. Both tests fail on the unfixed code —removeDomainRacingConcurrentRemovalMustNotThrowNPEwith the exact NPE from the issue — and pass with the fix.