Skip to content

memory/shared: eliminate flaky race in ConcurrentAccess test - #835

Open
ahmed0mousa wants to merge 1 commit into
eclipse-score:mainfrom
ahmed0mousa:ahmo_concurrent_access_flaky_test
Open

memory/shared: eliminate flaky race in ConcurrentAccess test#835
ahmed0mousa wants to merge 1 commit into
eclipse-score:mainfrom
ahmed0mousa:ahmo_concurrent_access_flaky_test

Conversation

@ahmed0mousa

@ahmed0mousa ahmed0mousa commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

The test's inserted_ bookkeeping flag was updated by the writer as a
separate step from the actual UpdateKnownRegion()/RemoveKnownRegion()
call, racing against the reader's plausibility check. A reader could
be paused between its own steps long enough for the writer to fully
insert and remove the same region, making the flag read false on both
sides of a bounds-check that returned true.

Use one shared_mutex per region: the writer holds it exclusively for
its whole insert-or-remove transaction, and the reader holds it shared
across its whole before-flag/bounds-check/after-flag triplet. This
makes the region's state provably frozen during a reader's check while
different regions remain fully concurrent, so the map's lock-free
behaviour is still genuinely exercised.

@LittleHuba LittleHuba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this will not remove the flakiness.
Scenario:

  1. Reader updates inserted_before
  2. Writer UpdatesKnownRegion + sets inserted
  3. Reader updates bounds
  4. Writer RemoveKnownRegion + sets inserted
  5. Reader updates inserted_after

Result: bounds.has_value() == true, but both inserted_before and inserted_after are false.

@ahmed0mousa
ahmed0mousa force-pushed the ahmo_concurrent_access_flaky_test branch from 0555adc to 25a17e1 Compare August 5, 2026 11:49
Comment thread score/memory/shared/memory_region_map_test.cpp Outdated
@ahmed0mousa
ahmed0mousa force-pushed the ahmo_concurrent_access_flaky_test branch from 25a17e1 to fbbbee0 Compare August 6, 2026 10:40
LittleHuba
LittleHuba previously approved these changes Aug 7, 2026
@LittleHuba
LittleHuba added this pull request to the merge queue Aug 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 7, 2026
Replace the per-region shared_mutex approach (which serialized reader
lookups against writer mutations for the same region, masking the very
reader/writer overlap this test exists to exercise) with a fully
lock-free design:

- The test is split into two phases (insert all regions, then remove
  them all), joined by a single-use barrier.
- The writer publishes progress via atomic start/finish counters per
  phase, updated with release semantics right before/after touching
  the map.
- Readers take acquire loads of these counters immediately before and
  after their own unsynchronized GetBoundsFromAddress() call, and use
  the resulting happens-before relationship (not a timing assumption)
  to assert only when the expected outcome is provably determined.
  When the writer genuinely overlaps a lookup, no plausibility
  assertion is made, only that a found region resolves to the correct
  bounds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants