Skip to content

Fix intermittent cache unit test segfault in Fedora CI - #13527

Merged
bneradt merged 1 commit into
apache:masterfrom
bneradt:fix-lock-waiting-holder-srcloc-race
Aug 12, 2026
Merged

bneradt merged 1 commit into
apache:masterfrom
bneradt:fix-lock-waiting-holder-srcloc-race

Conversation

@bneradt

@bneradt bneradt commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

The Fedora CI job fails every so often with a SIGSEGV in one of the
cache unit tests, always with the same stack: strrchr() called from
SourceLocation::str(), from lock_waiting(), from Mutex_trylock(). In
DEBUG builds a thread that fails to acquire a mutex reports the
holder's srcloc and handler, but those fields belong to whichever
thread holds the mutex, and a waiter that just failed to acquire it
holds nothing. That read races with the holder publishing the fields
on acquire and clearing them in Mutex_unlock(). Because
SourceLocation::str() loads file once for valid() and again for
strrchr(), and because the clear happens before the mutex is
released, a waiter can pass the validity check and then dereference a
null file. The cache unit tests are the only ones that enable the
locks debug tag, so they are the only ones that reach this code at
all.

This patch addresses this by reporting the waiting site rather than
the holder's. That SourceLocation is a MakeSourceLocation() temporary
owned by the caller, so nothing else can mutate it, and a holder
snapshot is stale the instant it is taken in any case. The holder is
still reported by lock_holding(), which runs from Mutex_unlock()
where the caller owns those fields.

Fixes: #13524

Co-Authored-By: Claude Opus 5 noreply@anthropic.com

@bneradt bneradt added this to the 11.0.0 milestone Aug 10, 2026
Copilot AI lite review requested due to automatic review settings August 10, 2026 18:33
@bneradt bneradt self-assigned this Aug 10, 2026

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bneradt bneradt added Core Bug Debug Support for system debugging Backport Marked for backport for an LTS patch release labels Aug 10, 2026
The Fedora CI job fails every so often with a SIGSEGV in one of the
cache unit tests, always with the same stack: strrchr() called from
SourceLocation::str(), from lock_waiting(), from Mutex_trylock(). In
DEBUG builds a thread that fails to acquire a mutex reports the
holder's srcloc and handler, but those fields belong to whichever
thread holds the mutex, and a waiter that just failed to acquire it
holds nothing. That read races with the holder publishing the fields
on acquire and clearing them in Mutex_unlock(). Because
SourceLocation::str() loads file once for valid() and again for
strrchr(), and because the clear happens before the mutex is
released, a waiter can pass the validity check and then dereference a
null file. The cache unit tests are the only ones that enable the
locks debug tag, so they are the only ones that reach this code at
all.

This patch addresses this by reporting the waiting site rather than
the holder's. That SourceLocation is a MakeSourceLocation() temporary
owned by the caller, so nothing else can mutate it, and a holder
snapshot is stale the instant it is taken in any case. The holder is
still reported by lock_holding(), which runs from Mutex_unlock()
where the caller owns those fields.

Fixes: apache#13524

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@bneradt
bneradt force-pushed the fix-lock-waiting-holder-srcloc-race branch from 16834b8 to 4176d83 Compare August 10, 2026 22:01
@bneradt bneradt changed the title Report the waiting site, not the holder's, when a try-lock fails Fix intermittent cache unit test segfault in Fedora CI Aug 10, 2026
@bryancall
bryancall requested a review from moonchen August 10, 2026 22:14
@bneradt bneradt removed Backport Marked for backport for an LTS patch release Debug Support for system debugging labels Aug 10, 2026

@masaori335 masaori335 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.

Makes sense. These variables are defined when it's DEBUG is defined.

#ifdef DEBUG
  const SourceLocation &location, const char *ahandler,
#endif

@bneradt
bneradt merged commit 8aebe2c into apache:master Aug 12, 2026
15 checks passed
@bneradt
bneradt deleted the fix-lock-waiting-holder-srcloc-race branch August 12, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debug builds: cache unit tests intermittently SIGSEGV in lock_waiting() reading the mutex holder's SourceLocation

3 participants