Add a dedicated monitor for graph observer list access - #298
Merged
Conversation
The observers list was previously only safe because every mutation went through the graph write lock; this adds synchronized(observers) at each access point so it also stays correct if auto-locking is disabled, and marks GraphObserverImpl.destroyed volatile for cross-thread visibility. Adds concurrency tests covering observer create/destroy racing against version-overflow reset and view destruction. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
An independent review found the existing concurrency tests pass even without the observers-monitor fix, since the default auto-locking config already serializes every access via the graph write lock — the monitor only matters when auto-locking is disabled, which nothing exercised. Adds a test under that config, verified to fail (ArrayIndexOutOfBoundsException) on the pre-fix code and pass on it. Also exercises edge-version overflow (previously only node version was covered) and synchronizes a leftover unguarded list read. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
synchronized(observers)guarding every access point of theGraphStore/GraphViewImplobserver lists (create, destroy,destroyAllObservers, version-reset iteration), so the lists stay correct even whenenableAutoLockingis disabled and the graph's read/write lock is a no-op.GraphObserverImpl.destroyedvolatilefor cross-thread visibility.GraphModelImplis kept as-is: it's what keeps view-existence checks atomic with concurrent view destruction, not just list-mutation safety — removing it (tried during development) reproducibly let an observer get registered on a view that was simultaneously being destroyed.Test plan
testConcurrentCreateAndDestroyGraphObserver(races observer create/destroy against forcedGraphVersionoverflow resets)testConcurrentCreateGraphObserverAndDestroyView(races observer creation againstdestroyView)mvn test— full suite passes (1647 tests, 0 failures)🤖 Generated with Claude Code