Closed Bug 845357 Opened 11 years ago Closed 11 years ago

TSan: Thread data race in ccapp_get_state vs. CCAppInit

Categories

(Core :: WebRTC, defect)

x86_64
Linux
defect
Not set
critical

Tracking

()

RESOLVED FIXED
mozilla22

People

(Reporter: posidron, Assigned: snandaku)

References

()

Details

(Keywords: sec-want, Whiteboard: [tsan][tsan-test-blocker][webrtc][blocking-webrtc+][qa-])

Attachments

(2 files, 2 obsolete files)

Attached file trace
During initial tests with ThreadSanitizer (LLVM version), we get a data race reported as described in the attached log. Trace was created on mozilla-central with changeset 122820:c233837cce08.

According to the TSan devs, most of the reported traces should be real data races, even though they can be "benign". We need to determine if the race can/should be fixed, or put on the ignore list. Even for benign races, TSan devs suggest to fix them (second priority), as they can also cause problems [1].

[1] http://software.intel.com/en-us/blogs/2013/01/06/benign-data-races-what-could-possibly-go-wrong
Looks like a simple date race where a memory barrier is needed after updating the state variable, or depending on if it's set to other values elsewhere it may need mutex locking.

In practice this is highly unlikely to cause problems, but that's hard to prove.
Assignee: nobody → ethanhugg
Whiteboard: [tsan][tsan-test-blocker] → [tsan][tsan-test-blocker][webrtc][webrtc-blocking+]
Whiteboard: [tsan][tsan-test-blocker][webrtc][webrtc-blocking+] → [tsan][tsan-test-blocker][webrtc][blocking-webrtc+]
Assignee: ethanhugg → snandaku
Took a stab at what might order the reads/writes of CCApp state races.
Attachment #731077 - Flags: review?(rjesup)
Attachment #731077 - Flags: review?(ethanhugg)
Comment on attachment 731077 [details] [diff] [review]
Patch to order reads/writes of CCApp state between threads


Suhas, this patch looks a bit odd to me it doesn't have the usual header with name and date like this:
# HG changeset patch
# User Ethan Hugg <ethanhugg@gmail.com>
# Date 1353004707 28800

And it also has Windows-style CRLFs throughout which means folks will get patching errors.  Did you use bzexport to upload this patch?
Hi Ethan .. My bzexport is giving trouble .Hence i had to upload it manually. Let me give it another try.
Uploading hg export way this time untill my bzexport issue gets fixed.
Attachment #731077 - Attachment is obsolete: true
Attachment #731077 - Flags: review?(rjesup)
Attachment #731077 - Flags: review?(ethanhugg)
Attachment #731219 - Flags: review?(rjesup)
Attachment #731219 - Flags: review?(ethanhugg)
Comment on attachment 731219 [details]
Patch to order writes/reads of CCApp state between threads

Review of attachment 731219 [details]:
-----------------------------------------------------------------

r+; I understand ethan has some nits to address.  I can land if needed over the weekend once they're addressed
Attachment #731219 - Flags: review?(rjesup) → review+
thanks jesup .. Once i hear from Ethan, I shall upload a new version based for you to check in.
Comment on attachment 731219 [details]
Patch to order writes/reads of CCApp state between threads

Review of attachment 731219 [details]:
-----------------------------------------------------------------

::: media/webrtc/signaling/src/sipcc/core/ccapp/ccprovider.c
@@ +179,5 @@
> +// Sets up mutex needed for protecting state variables.
> +static cc_int32_t InitInternal();
> +
> +// Handy macro for executing memory barrier on CCApp State updates.
> +#define ENTER_MEMORY_BARRIER \

I think this macro name is a bit too generic.  I would suggest getting CCAPPSTATE in there like ENTER_CCAPPSTATE_PROTECT for example.

@@ +314,3 @@
>  cc_reg_state_t ccapp_get_state() {
> +   // wait till the ongoing modification is
> +   // completed

I believe we have been putting /* */ in C code and // in C++ code.

@@ +344,5 @@
> +  }
> +  // Bug 845357
> +  ENTER_MEMORY_BARRIER;
> +  gCCApp.state = CC_CREATED_IDLE;
> +  canReadCCAppState = 1;

Is this needed? This is also set to 1 in EXIT_MEMORY_BARRIER

@@ +1241,2 @@
>          gCCApp.state = CC_OOS_FAILOVER;
> +        EXIT_MEMORY_BARRIER;

This pattern repeats a lot, how about a static function ccapp_set_state()?
Attachment #731219 - Flags: review?(ethanhugg) → review+
Take r+ forward from Ethan and Randell with comments addressed.
Attachment #731492 - Flags: review?(ethanhugg)
Attachment #731492 - Flags: checkin?(rjesup)
Attachment #731219 - Attachment is obsolete: true
Attachment #731219 - Attachment is patch: false
Attachment #731492 - Flags: review?(ethanhugg)
Attachment #731492 - Flags: review+
Attachment #731492 - Flags: checkin?(rjesup)
Attachment #731492 - Flags: checkin+
https://hg.mozilla.org/mozilla-central/rev/8c4acb0bd10d
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Whiteboard: [tsan][tsan-test-blocker][webrtc][blocking-webrtc+] → [tsan][tsan-test-blocker][webrtc][blocking-webrtc+][qa-]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: