ThreadSanitizer: data race [@ mozilla::net::CacheEntry::InvokeCallback] vs. [@ mozilla::net::CacheEntry::Purge]
Categories
(Core :: Networking, defect, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox73 | --- | wontfix |
People
(Reporter: decoder, Assigned: mayhemer)
References
(Blocks 1 open bug)
Details
(Whiteboard: [necko-triaged])
Attachments
(1 file, 1 obsolete file)
22.20 KB,
text/plain
|
Details |
The attached crash information was detected while running CI tests with ThreadSanitizer on mozilla-central revision c0a6eb95b65c.
This is very likely a benign race. Looking at the comments in the affected code, the race on mState
should not be an issue because it transitions from READY
to REVALIDATING
and the code racing with this does not care about either of these states. I am concerned about suppressing this entire function though, because it means we don't find any other races related to the CacheEntry callbacks.
From a correctness standpoint, if mState
is shared across threads, then it should be an atomic though, otherwise the code can be optimized to not see the updates performed to that variable in some cases. Depending on the order assumptions of this code, it might even have to be stricter than relaxed to avoid reordering, which could be the source of subtle bugs.
General information about TSan reports
Why fix races?
Data races are undefined behavior and can cause crashes as well as correctness issues. Compiler optimizations can cause racy code to have unpredictable and hard-to-reproduce behavior.
Rating
If you think this race can cause crashes or correctness issues, it would be great to rate the bug appropriately as P1/P2 and/or indicating this in the bug. This makes it a lot easier for us to assess the actual impact that these reports make and if they are helpful to you.
False Positives / Benign Races
Typically, races reported by TSan are not false positives [1], but it is possible that the race is benign. Even in this case it would be nice to come up with a fix if it is easily doable and does not regress performance. Every race that we cannot fix will have to remain on the suppression list and slows down the overall TSan performance. Also note that seemingly benign races can possibly be harmful (also depending on the compiler, optimizations and the architecture) [2][3].
[1] One major exception is the involvement of uninstrumented code from third-party libraries.
[2] http://software.intel.com/en-us/blogs/2013/01/06/benign-data-races-what-could-possibly-go-wrong
[3] How to miscompile programs with "benign" data races: https://www.usenix.org/legacy/events/hotpar11/tech/final_files/Boehm.pdf
Suppressing unfixable races
If the bug cannot be fixed, then a runtime suppression needs to be added in mozglue/build/TsanOptions.cpp
. The suppressions match on the full stack, so it should be picked such that it is unique to this particular race. The bug number of this bug should also be included so we have some documentation on why this suppression was added.
Reporter | ||
Comment 1•5 years ago
|
||
Comment 3•5 years ago
|
||
Honza knows this part of the cache better
![]() |
Assignee | |
Comment 4•5 years ago
|
||
I think we should add a lock over CacheEntry::Purge
(or parts of it). Making mState an atomic is a total overkill with a bad perf impact. I decided to use a lock instead of atomics, because the code is already complex enough and we need to move several members based on state transitions where other threads need to see a consistent state of all the affected members.
![]() |
Assignee | |
Updated•5 years ago
|
Updated•5 years ago
|
![]() |
Assignee | |
Comment 5•5 years ago
|
||
![]() |
Assignee | |
Updated•5 years ago
|
![]() |
Assignee | |
Comment 7•5 years ago
|
||
We should update https://searchfox.org/mozilla-central/rev/31d8600b73dc85b4cdbabf45ac3f1a9c11700d8e/mozglue/build/TsanOptions.cpp#181-182
Updated•5 years ago
|
Reporter | ||
Comment 8•5 years ago
|
||
(In reply to Honza Bambas (:mayhemer) from comment #7)
We should update https://searchfox.org/mozilla-central/rev/31d8600b73dc85b4cdbabf45ac3f1a9c11700d8e/mozglue/build/TsanOptions.cpp#181-182
Making a try-run for this now and will push a patch to this bug. Leaving needinfo for that purpose.
Reporter | ||
Comment 9•5 years ago
|
||
Reporter | ||
Comment 10•5 years ago
|
||
Green on try :)
Comment 11•5 years ago
|
||
Comment 12•5 years ago
|
||
Comment 13•5 years ago
|
||
Backed out for tsan fails on CacheEntry.cpp
backout: https://hg.mozilla.org/integration/autoland/rev/8a55b81e0bdc7fa79ef9ee96cdcfc3d1eac61566
failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=309167292&repo=autoland&lineNumber=2492
![]() |
Assignee | |
Comment 14•5 years ago
|
||
Worth filing a new bug and fixing it separately.
Reporter | ||
Comment 15•5 years ago
|
||
(In reply to Honza Bambas (:mayhemer) from comment #14)
Worth filing a new bug and fixing it separately.
I filed bug 1652300 for this and we can do the fix + suppression removal there instead.
Updated•5 years ago
|
Description
•