Closed Bug 1316011 Opened 8 years ago Closed 8 years ago

[findbugs] [VO] Increment of volatile field org.mozilla.gecko.sync.synchronizer.SerialRecordConsumer.counter in org.mozilla.gecko.sync.synchronizer.SerialRecordConsumer.stored()

Categories

(Firefox for Android Graveyard :: General, defect, P3)

All
Android
defect

Tracking

(firefox53 fixed)

RESOLVED FIXED
Firefox 53
Tracking Status
firefox53 --- fixed

People

(Reporter: sebastian, Assigned: sebastian, Mentored)

References

Details

(Whiteboard: [lang=java][good first bug])

Attachments

(2 files, 1 obsolete file)

Increment of volatile field org.mozilla.gecko.sync.synchronizer.SerialRecordConsumer.counter in org.mozilla.gecko.sync.synchronizer.SerialRecordConsumer.stored() "This code increments a volatile field. Increments of volatile fields aren't atomic. If more than one thread is incrementing the field at the same time, increments could be lost."
To start, set up a build environment - you can see the instructions here: https://developer.mozilla.org/en-US/docs/Mozilla/Developer_guide/Build_Instructions/Simple_Firefox_for_Android_build Then, you'll need to upload a patch - see: http://mozilla-version-control-tools.readthedocs.io/en/latest/mozreview/commits.html If you need any help, you can reply to this bug, or feel free to message me on IRC - my nick is "sebastian" and you can find me and other helpful folks in #mobile. If you need IRC setup instructions, see https://wiki.mozilla.org/IRC
Hi I want to work on fixing this bug. What do you suggest I do? Should I change the variable counter from Long to AtomicLong?
Hi, I cannot find this file in mozilla-central. I'm looking in mozilla-central/mobile/android/base/java/org/gecko/ but there is no sync directory. Am I looking in the right directory?
Flags: needinfo?(s.kaspari)
(In reply to mddrill from comment #3) > Hi, I cannot find this file in mozilla-central. I'm looking in > mozilla-central/mobile/android/base/java/org/gecko/ but there is no sync > directory. Am I looking in the right directory? It's here: https://dxr.mozilla.org/mozilla-central/source/mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/SerialRecordConsumer.java
Flags: needinfo?(s.kaspari)
:Sebastian you haven't given me any response yet!!
(In reply to archit garg[:archit] from comment #5) > :Sebastian you haven't given me any response yet!! Oh, sorry, I did miss that. Make sure to use the "need more information" flag and I won't be able to miss it. :) > What do you suggest I do? Should I change the variable counter from Long to Yeah, this is one option. I see that most access is synchronized. If all access is synchronized then we can just remove the 'volatile' keyword because all threads will see the uncached value anyways.
Hi sebastian! I want to work on this bug if nobody is working on it
Hi sebastian! Can you please review my code https://reviewboard-hg.mozilla.org/gecko/rev/73d8cea7d424? I have removed volatile keyword using AtomicLong and synchronization of counter is done!
Assignee: nobody → owaiskazi19
Status: NEW → ASSIGNED
Comment on attachment 8818228 [details] Bug 1316011-Removed use of volatile keyword and thread synchronization is done using AtomicLong Part 2. https://reviewboard.mozilla.org/r/98374/#review99362 This patch looks like it does not belong here. If you only want to push a single commit to reviewboard (and assuming you are using mercurial) then you can use "hg push -c CHANGESET".
Attachment #8818228 - Flags: review?(s.kaspari) → review-
Comment on attachment 8818229 [details] Bug 1316011-Removed use of volatile keyword and thread synchronization is done using AtomicLong https://reviewboard.mozilla.org/r/98376/#review99364 ::: mobile/android/services/src/main/java/org/mozilla/gecko/sync/synchronizer/SerialRecordConsumer.java:86 (Diff revision 1) > - long counterNow = this.counter; > - Logger.info(LOG_TAG, "Consumer is done. Processed " + counterNow + ((counterNow == 1) ? " record." : " records.")); > + AtomicLong counterNow = this.counter; > + Logger.info(LOG_TAG, "Consumer is done. Processed " + counterNow + ((counterNow.get() == 1) ? " record." : " records.")); > delegate.consumerIsDone(stopImmediately); It looks like the idea here is to cache the current value inside the method so that the value does not change between logging it and deciding between "record" and "records". Either get the value once and keep the rest of the code: > long counterNow = counter.get(); Or simplify the log message and just append "record(s)". It's only a log message after all.
Attachment #8818229 - Flags: review?(s.kaspari)
I pushed the current version of the patch to "try" so that we can see if the tests catch any errors with the new code: https://treeherder.mozilla.org/#/jobs?repo=try&revision=f5fab76461be
Hi sebastian! So should i create a new patch or wait for the tests to catch any errors?
https://treeherder.mozilla.org/#/jobs?repo=try&revision=f5fab76461be&selectedJob=32823613 It is 100% done can you elaborate me with the results please
The failures are related to the other attached patch. Just update the patch (See comment 12) and push it. After that I'll push your updated version to try again.
Attachment #8818229 - Attachment is obsolete: true
Comment on attachment 8818228 [details] Bug 1316011-Removed use of volatile keyword and thread synchronization is done using AtomicLong Part 2. https://reviewboard.mozilla.org/r/98374/#review99454
Attachment #8818228 - Flags: review?(s.kaspari) → review+
Comment on attachment 8818228 [details] Bug 1316011-Removed use of volatile keyword and thread synchronization is done using AtomicLong Part 2. https://reviewboard.mozilla.org/r/98374/#review99456 https://treeherder.mozilla.org/#/jobs?repo=try&revision=18108585b3d5
Comment on attachment 8818228 [details] Bug 1316011-Removed use of volatile keyword and thread synchronization is done using AtomicLong Part 2. https://reviewboard.mozilla.org/r/98374/#review99458 https://treeherder.mozilla.org/#/jobs?repo=try&revision=18108585b3d5
Keywords: checkin-needed
Pushed by ryanvm@gmail.com: https://hg.mozilla.org/integration/autoland/rev/82753b1778fa Removed use of volatile keyword and thread synchronization is done using AtomicLong Part 2. r=sebastian
Keywords: checkin-needed
Hi sebastian! Is the bug complete now?
With all due respect to everyone involved, this bug should probably be WONTFIXed and the patch backed out. Using an AtomicLong here, for a value that's only present for logging, is overkill. And more thorough analysis would show that there is likely to be no concurrency issue here -- after all, this isn't called SerialRecordConsumer for nothing. Automated error finding tools should not cause knee-jerk patches to stable code.
Sorry, this is my mistake. I should have analyzed the code more - just because of the synchronization blocks I was assuming this was multi-threaded code (and 'counter' was defined as volatile?). I'll reopen and back out if needed.
Assignee: owaiskazi19 → s.kaspari
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 53
Is this bug fixed now?
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Comment on attachment 8824126 [details] Bug 1316011 - findbugs: Enable VO_VOLATILE_INCREMENT check and ignore false positive in SerialRecordConsumer. https://reviewboard.mozilla.org/r/102676/#review104110
Attachment #8824126 - Flags: review?(walkingice0204) → review+
Pushed by s.kaspari@gmail.com: https://hg.mozilla.org/integration/autoland/rev/482d24b7c611 findbugs: Enable VO_VOLATILE_INCREMENT check and ignore false positive in SerialRecordConsumer. r=walkingice
Status: REOPENED → RESOLVED
Closed: 8 years ago8 years ago
Resolution: --- → FIXED
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: