Repository navigation
tests: a per-process temp file for ariadne_media_test's encode() - #1068
Merged
Merged
Conversation
encode() named its temp file from std::hash<std::thread::id> of the calling thread alone. ctest runs each case in its own process, several at once under -j, and on macOS the main thread's pthread_t lives in the dyld shared cache at the same address in every process for a boot, so every test process picked the same file. Concurrent cases wrote, read and removed each other's file and decoding saw "png: no image data" (MediaDecode.* on #1054's macOS Release recipe job). Name the file from the process id plus a per-process atomic call counter, with the CVC_GETPID() macro the hdf5/utility/volume_io tests already use. The file is still closed before the remove for Windows.
stop() stores stop_requested_ with release, but run_steps(), idle_wait() and the async run_loop() read it relaxed, so nothing ordered stop()'s store before what the run's owner does once run() returns. An owner may destroy the scheduler at once (Hazards.ASchedulerStoppedFromAnotherThread- MayGoWhenItsRunReturns does), and that delete then raced the store: clang-tsan reported it on master (04b72a3) and on unrelated PRs, as a data race between ~scheduler()'s operator delete and stop()'s atomic<bool>::store. Read the flag with acquire in all three places. On x86 that is the same plain load; elsewhere it is one ordered load per loop iteration.
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.
ariadne_media_test'sencode()writes each test picture to a temp file, reads it back and removes it. The file name came from the thread id alone:ctest runs each gtest case in its own process, and under
-jseveral run at once. On macOS the main thread'spthread_tis a static inside libsystem_pthread, which sits in the dyld shared cache. That cache is mapped at the same address in every process for a given boot, so every test process got the same thread id hash and the SAME file name. Concurrent cases wrote, read and removed each other's file, so the bytescvc::write_imagehad just written came back empty and decoding failed with "png: no image data". (hdf5_test.cppalready notes the same macOS thread-id reuse.)Evidence
#1054's
recipe / macos-latest / Releasejob (run 42459028712, job 128664142118):MediaDecode.PngJpegBmpGifDecodeFromMemory, 760MediaDecode.LimitsRefuseBeforeDecodingand 761MediaDecode.AnimatedGifAndWebpKeepTheirFramesstarted within 0.8 s of each other and all failed. Theiruntil-pass:3retries overlapped too: 757 and 760 failed all three tries, which failed the job ("2 tests failed out of 6423").MediaCache.LoadsOnceAndSharesTheFetchBetweenBoxesandMediaBackground.FtxuiDrawsHalfBlocksBehindTextAndABannerAbove, the other users ofencode(), each failed once and then passed.#1054 itself only swaps cmake, ninja and pkg-config for cvcpkg's, and its ImageMagick, libpng and compiler match #1050's passing run. So the failure was this race, not that change.
Fix
The name is now the process id plus a per-process atomic call counter:
ariadne_media_test_<pid>_<n>.<ext>. That makes it unique across concurrent ctest processes and across threads and calls within one process. It uses the sameCVC_GETPID()macro ashdf5_test.cpp,hdf5_volume_test.cpp,utility_test.cpp,volume_io_test.cppandvolume_io_extra_test.cpp. The file is still closed before the remove, for Windows.No other test in
src/cvc/testsnames temp files from the thread id alone. The five tests above already add the pid and a counter, andthread_pool_test.cpphashes the thread id only to count distinct workers.Testing
Windows (MSVC 14.44 under vcvars64, static Release, cvcpkg deps): built
ariadne_media_testand ran all 44 of its cases at the same time withctest -R "^(Media|AriadneReactiveBudget)" -j 16 --repeat until-fail:10. All 440 runs passed, and noariadne_media_test_*file was left in%TEMP%.Windows thread ids are unique across live processes, so the old name never collided there. This run checks that the new name holds up under concurrency. The macOS Release lane in this PR's CI is the real check.
Second commit: the scheduler stop() race
This PR's first CI run passed
recipe / macos-latest / ReleaseandDebug, butsanitizers / clang-tsanfailed. TSan reported a race instate_exec_hazards_test(Hazards.ASchedulerStoppedFromAnotherThreadMayGoWhenItsRunReturns) between~scheduler()andstop()'s store of the stop flag. That race was already on master, whose own run at 04b72a3 failed the same way, and has nothing to do with the media test.The second commit is a cherry-pick of #1073 ("state_exec: a run reads stop()'s flag with acquire"), so this PR's tsan leg can pass. #1073 explains the cause and the fix. Whichever of the two merges first brings the change in. The other then carries an identical diff for those five files, so it merges without conflicts there.