Fix an intermittent cache unit test deadlock at exit - #13535
Merged
Conversation
The cache unit test harness starts the event and net processors but never stops them, so every test binary reaches exit() with ET_NET threads still running. Static destruction then frees globals out from under those threads: the records table in RecCore.cc is destroyed while a still-initializing event thread reads it through RecGetRecordInt(), and the ts::Metrics storage blob is released while NetHandler's activity loop increments a counter into it. Both are heap-use-after-frees, and under ASan the reporting thread races the exiting main thread. Usually the process dies first and the report is truncated to two lines with a zero exit status, so ctest reports a pass; occasionally the report deadlocks instead and the test hangs until ctest times it out after 1500 seconds. The short tests that never touch the cache lose this race most often, which is why CacheAggregateWriteBuffer and CacheStripe are the ones that fail. This addresses the deadlock at its source by giving the harness's Catch2 listener a testRunEnded hook that shuts the event system down and joins the event threads before the test binary returns from main. Once the threads are gone, static destruction has no concurrent reader to race, so neither use-after-free can be reported and the ASan reporting deadlock cannot arise. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
cmcfarlen
approved these changes
Aug 11, 2026
cmcfarlen
pushed a commit
that referenced
this pull request
Aug 12, 2026
The cache unit test harness starts the event and net processors but never stops them, so every test binary reaches exit() with ET_NET threads still running. Static destruction then frees globals out from under those threads: the records table in RecCore.cc is destroyed while a still-initializing event thread reads it through RecGetRecordInt(), and the ts::Metrics storage blob is released while NetHandler's activity loop increments a counter into it. Both are heap-use-after-frees, and under ASan the reporting thread races the exiting main thread. Usually the process dies first and the report is truncated to two lines with a zero exit status, so ctest reports a pass; occasionally the report deadlocks instead and the test hangs until ctest times it out after 1500 seconds. The short tests that never touch the cache lose this race most often, which is why CacheAggregateWriteBuffer and CacheStripe are the ones that fail. This addresses the deadlock at its source by giving the harness's Catch2 listener a testRunEnded hook that shuts the event system down and joins the event threads before the test binary returns from main. Once the threads are gone, static destruction has no concurrent reader to race, so neither use-after-free can be reported and the ASan reporting deadlock cannot arise. Co-authored-by: Claude Opus 5 <noreply@anthropic.com> (cherry picked from commit 0c18d46)
Contributor
|
Cherry-picked to the 10.2.x branch as 51c0e97 for the 10.2.0 release. |
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.
The cache unit test harness starts the event and net processors but
never stops them, so every test binary reaches exit() with ET_NET
threads still running. Static destruction then frees globals out from
under those threads: the records table in RecCore.cc is destroyed while
a still-initializing event thread reads it through RecGetRecordInt(),
and the ts::Metrics storage blob is released while NetHandler's activity
loop increments a counter into it. Both are heap-use-after-frees, and
under ASan the reporting thread races the exiting main thread. Usually
the process dies first and the report is truncated to two lines with a
zero exit status, so ctest reports a pass; occasionally the report
deadlocks instead and the test hangs until ctest times it out after
1500 seconds. The short tests that never touch the cache lose this race
most often, which is why CacheAggregateWriteBuffer and CacheStripe are
the ones that fail.
This addresses the deadlock at its source by giving the harness's Catch2
listener a testRunEnded hook that shuts the event system down and joins
the event threads before the test binary returns from main. Once the
threads are gone, static destruction has no concurrent reader to race,
so neither use-after-free can be reported and the ASan reporting
deadlock cannot arise.
Verification
Built with
--preset ci-rocky(ASan, Debug) and looped the affectedbinaries directly, since a full
ctestpass rarely trips the race and thefailing runs still exit zero:
CacheAggregateWriteBufferCacheStripeThe 15 reports split into the two use-after-frees described above: six
READ of size 8ing_records_ht.find(), reached frominitialize_thread_for_net()on a thread that has not finished starting,and nine
WRITE of size 8ints::Metrics::Counter::increment()fromNetHandler::waitForActivity(). Both are freed by the main thread fromstatic destruction.
All 20
test_cache*plustest_ConfigVolumestargets pass with the fix, sojoining the event threads does not hang the tests that drive the cache and
already call
TSSystemState::shut_down_event_system()themselves.Ten full
ctest -j4passes were clean, which is expected: this bug reportsa zero exit status in the overwhelming majority of cases and is only visible
in CI when the ASan report deadlocks instead, as in the Rocky Linux build
that prompted this patch.