Skip to content

Add a dedicated monitor for graph observer list access - #298

Merged
mbastian merged 2 commits into
masterfrom
graph-observer-lock-monitor
Sep 4, 2026
Merged

Add a dedicated monitor for graph observer list access#298
mbastian merged 2 commits into
masterfrom
graph-observer-lock-monitor

Conversation

@mbastian

@mbastian mbastian commented Sep 4, 2026

Copy link
Copy Markdown
Member

Summary

  • Add synchronized(observers) guarding every access point of the GraphStore/GraphViewImpl observer lists (create, destroy, destroyAllObservers, version-reset iteration), so the lists stay correct even when enableAutoLocking is disabled and the graph's read/write lock is a no-op.
  • Mark GraphObserverImpl.destroyed volatile for cross-thread visibility.
  • The graph write lock around observer create/destroy in GraphModelImpl is 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

  • Added testConcurrentCreateAndDestroyGraphObserver (races observer create/destroy against forced GraphVersion overflow resets)
  • Added testConcurrentCreateGraphObserverAndDestroyView (races observer creation against destroyView)
  • mvn test — full suite passes (1647 tests, 0 failures)

🤖 Generated with Claude Code

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>
@mbastian mbastian added this to the 0.8.8 milestone Sep 4, 2026
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>
@mbastian
mbastian merged commit 4159fb1 into master Sep 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant