Closed Bug 1607212 Opened 2 years ago Closed 2 years ago

ThreadSanitizer: data race [@ mozilla::net::CacheEntry::InvokeCallback] vs. [@ mozilla::net::CacheEntry::Purge]

Categories

(Core :: Networking, defect, P2)

x86_64
Linux
defect

Tracking

()

RESOLVED DUPLICATE of bug 1615121
Tracking Status
firefox73 --- wontfix

People

(Reporter: decoder, Assigned: mayhemer)

References

(Blocks 1 open bug)

Details

(Whiteboard: [necko-triaged])

Attachments

(1 file, 1 obsolete file)

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.

Michal maybe this is easy to correct?

Flags: needinfo?(michal.novotny)

Honza knows this part of the cache better

Flags: needinfo?(michal.novotny) → needinfo?(honzab.moz)

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.

Flags: needinfo?(honzab.moz)
Priority: -- → P2
Whiteboard: [necko-triaged]
Assignee: nobody → honzab.moz
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 1615121

(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.

Status: RESOLVED → REOPENED
Resolution: DUPLICATE → ---

Green on try :)

Pushed by choller@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/e106c60b7be4
Update TSan suppressions for fixed Necko cache race. r=mayhemer
Backout by ncsoregi@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/8a55b81e0bdc
Backed out changeset e106c60b7be4 for tsan fails on CacheEntry.cpp. CLOSED TREE

Worth filing a new bug and fixing it separately.

(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.

Status: REOPENED → RESOLVED
Closed: 2 years ago2 years ago
Flags: needinfo?(choller)
Resolution: --- → DUPLICATE
Duplicate of bug: 1615121
Attachment #9162477 - Attachment is obsolete: true
You need to log in before you can comment on or make changes to this bug.