Protect test hook callback with mutex for TSan safety#61
Merged
bghgary merged 2 commits intomicrosoft:masterfrom Apr 16, 2026
Merged
Protect test hook callback with mutex for TSan safety#61bghgary merged 2 commits intomicrosoft:masterfrom
bghgary merged 2 commits intomicrosoft:masterfrom
Conversation
The beforeWaitCallback global std::function was accessed from multiple threads without synchronization. Add a dedicated mutex and use copy-under-lock, invoke-after-unlock pattern to avoid holding the lock during arbitrary callback execution. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR addresses a ThreadSanitizer (TSan) data race in the blocking_concurrent_queue test hook by synchronizing access to the global beforeWaitCallback used in ARCANA_TEST_HOOKS builds.
Changes:
- Added a dedicated
callbackMutexto guard reads/writes ofbeforeWaitCallback. - Introduced
detail::invoke_before_wait_callback()to copy the callback under lock and invoke it after releasing the callback lock. - Updated
internal_popandinternal_drainto call the new helper instead of invoking the global callback directly.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CedricGuillemet
approved these changes
Apr 16, 2026
ryantrem
approved these changes
Apr 16, 2026
bghgary
added a commit
to bghgary/JsRuntimeHost
that referenced
this pull request
Apr 16, 2026
- Add tsan_suppressions.txt to suppress JavaScriptCore/WTF/bmalloc internal data races on Ubuntu (not fixable by us) - Wire suppressions into linux.yml for TSan jobs via TSAN_OPTIONS - Point arcana.cpp at upstream (microsoft/arcana.cpp#61 merged) - Update UrlLib fork SHA (post-rebase, pending BabylonJS/UrlLib#27) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
[Created by Copilot on behalf of @bghgary]
Protect the
beforeWaitCallbacktest hook with a mutex for TSan safety.Problem
The
beforeWaitCallbackglobal inblocking_concurrent_queuewas unprotected — one thread could be reading/invoking it while another calledset_before_wait_callback. TSan flags this as a data race.Fix
callbackMutexto guardbeforeWaitCallbackaccessset_before_wait_callback: acquires lock, moves new callback ininvoke_before_wait_callback(newdetailhelper): copies callback under the lock, invokes after releasing — avoids potential deadlocks if the callback interacts with other locksinternal_popandinternal_draincall the helper instead of inlining the pattern