Repository navigation
fix data race in SqliteLogger::callback - #1237
Open
aysha-afrah26 wants to merge 1 commit into
Open
aysha-afrah26 wants to merge 1 commit into
aysha-afrah26 wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Status-change callbacks are not serialized: a ThreadedAction that completes calls setStatus from its worker thread, so two actions finishing at the same time (or one finishing while the main thread ticks) invoke SqliteLogger::callback concurrently. The callback updated monotonic_timestamp_ and the starting_time_ map before taking queue_mutex_, which is a data race on the timestamp and can corrupt the unordered_map on a concurrent insert. When two racing callbacks compute the same timestamp, the later INSERT also violates the PRIMARY KEY of the Transitions table and the uncaught exception in the writer thread terminates the process. Groot2Publisher and FileLogger2 already lock inside their callback for the same reason. The fix computes the timestamp and duration under the queue_mutex_ that the function already takes to push the transition, so there is no new member and no API or ABI change; single-threaded behavior is unchanged. Added the regression test SqliteLogger_ConcurrentTransitions, which ThreadSanitizer flags at the monotonic_timestamp_ update before the fix and reports clean after (the sanitizers CI job runs the suite under TSan). Full ctest on macOS is 546/547 in Release and 549/551 under TSan, with the failures (SqliteLogger_ExecSqlStatement, Parallel.FailingParallel, MultipleLoggers) verified to fail identically on unpatched master. pre-commit (clang-format, codespell) passes on the touched files.