Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Issue 10823329: rlz/mac: Make sure a crashing process doesn't leave a stale lockfile behind. (Closed)

Created:
8 years, 4 months ago by Nico
Modified:
8 years, 4 months ago
CC:
chromium-reviews, Scott Hess - ex-Googler, Roger Tawa OOO till Jul 10th
Visibility:
Public.

Description

rlz/mac: Make sure a crashing process doesn't leave a stale lockfile behind. Don't use NSDistributedLock, which uses a lock that isn't cleaned up on unexpected program termination, and which strongly recommends to not call -breakLock (which makes this class fairly pointless). Instead, use a flock(), which is cleaned up by the OS on process exit. Suggested by shess@. BUG=141108 Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=151723

Patch Set 1 #

Patch Set 2 : flock #

Patch Set 3 : xxx #

Patch Set 4 : actually #

Patch Set 5 : . #

Total comments: 23

Patch Set 6 : . #

Total comments: 8

Patch Set 7 : more comments #

Total comments: 4

Patch Set 8 : . #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+77 lines, -20 lines) Patch
M rlz/lib/rlz_lib_test.cc View 1 2 3 4 5 6 3 chunks +51 lines, -1 line 0 comments Download
M rlz/mac/lib/rlz_value_store_mac.mm View 1 2 3 4 5 6 7 5 chunks +26 lines, -19 lines 2 comments Download

Messages

Total messages: 15 (0 generated)
Nico
On second thought, the "breaks test" comment I left on the bug is rubbish: The ...
8 years, 4 months ago (2012-08-15 00:24:56 UTC) #1
Scott Hess - ex-Googler
I'm sure the headlines will read "Chromium includes Flock". http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store_mac.mm File rlz/mac/lib/rlz_value_store_mac.mm (right): http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store_mac.mm#newcode238 rlz/mac/lib/rlz_value_store_mac.mm:238: ...
8 years, 4 months ago (2012-08-15 00:44:38 UTC) #2
Mark Mentovai
http://codereview.chromium.org/10823329/diff/9002/rlz/lib/rlz_lib_test.cc File rlz/lib/rlz_lib_test.cc (right): http://codereview.chromium.org/10823329/diff/9002/rlz/lib/rlz_lib_test.cc#newcode800 rlz/lib/rlz_lib_test.cc:800: Blank line nit. http://codereview.chromium.org/10823329/diff/9002/rlz/lib/rlz_lib_test.cc#newcode848 rlz/lib/rlz_lib_test.cc:848: // make the test ...
8 years, 4 months ago (2012-08-15 00:50:54 UTC) #3
Nico
Also added the required third argument to open() 9_9 http://codereview.chromium.org/10823329/diff/9002/rlz/lib/rlz_lib_test.cc File rlz/lib/rlz_lib_test.cc (right): http://codereview.chromium.org/10823329/diff/9002/rlz/lib/rlz_lib_test.cc#newcode848 rlz/lib/rlz_lib_test.cc:848: ...
8 years, 4 months ago (2012-08-15 03:24:12 UTC) #4
Nico
On 2012/08/15 00:44:38, shess wrote: > I'm sure the headlines will read "Chromium includes Flock". ...
8 years, 4 months ago (2012-08-15 03:25:09 UTC) #5
Mark Mentovai
http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store_mac.mm File rlz/mac/lib/rlz_value_store_mac.mm (right): http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store_mac.mm#newcode272 rlz/mac/lib/rlz_value_store_mac.mm:272: file_lock_ = 0; Nico wrote: > On 2012/08/15 00:50:54, ...
8 years, 4 months ago (2012-08-15 13:36:28 UTC) #6
Nico
http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store_mac.mm File rlz/mac/lib/rlz_value_store_mac.mm (right): http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store_mac.mm#newcode282 rlz/mac/lib/rlz_value_store_mac.mm:282: elapsedMS += kSleepPerTryMS; On 2012/08/15 13:36:28, Mark Mentovai wrote: ...
8 years, 4 months ago (2012-08-15 14:52:50 UTC) #7
Roger Tawa OOO till Jul 10th
http://codereview.chromium.org/10823329/diff/14001/rlz/lib/rlz_lib_test.cc File rlz/lib/rlz_lib_test.cc (right): http://codereview.chromium.org/10823329/diff/14001/rlz/lib/rlz_lib_test.cc#newcode873 rlz/lib/rlz_lib_test.cc:873: } Should this test be wrapped in a #if ...
8 years, 4 months ago (2012-08-15 15:10:23 UTC) #8
Mark Mentovai
http://codereview.chromium.org/10823329/diff/4002/rlz/mac/lib/rlz_value_store_mac.mm File rlz/mac/lib/rlz_value_store_mac.mm (right): http://codereview.chromium.org/10823329/diff/4002/rlz/mac/lib/rlz_value_store_mac.mm#newcode301 rlz/mac/lib/rlz_value_store_mac.mm:301: close(file_lock_); Nico wrote: > On 2012/08/15 13:36:28, Mark Mentovai ...
8 years, 4 months ago (2012-08-15 16:10:00 UTC) #9
Nico
http://codereview.chromium.org/10823329/diff/4002/rlz/mac/lib/rlz_value_store_mac.mm File rlz/mac/lib/rlz_value_store_mac.mm (right): http://codereview.chromium.org/10823329/diff/4002/rlz/mac/lib/rlz_value_store_mac.mm#newcode301 rlz/mac/lib/rlz_value_store_mac.mm:301: close(file_lock_); On 2012/08/15 16:10:00, Mark Mentovai wrote: > Nico ...
8 years, 4 months ago (2012-08-15 17:02:27 UTC) #10
Mark Mentovai
LGTM.
8 years, 4 months ago (2012-08-15 17:27:33 UTC) #11
Mark Mentovai
thakis@chromium.org wrote: > flock is even explicitly mentioned on the list in > https://groups.google.com/**forum/?fromgroups#!msg/** > ...
8 years, 4 months ago (2012-08-15 17:31:16 UTC) #12
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/thakis@chromium.org/10823329/3005
8 years, 4 months ago (2012-08-15 17:36:43 UTC) #13
Scott Hess - ex-Googler
lame-duck comments not needing any action. http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store_mac.mm File rlz/mac/lib/rlz_value_store_mac.mm (right): http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store_mac.mm#newcode238 rlz/mac/lib/rlz_value_store_mac.mm:238: int file_lock_; On ...
8 years, 4 months ago (2012-08-15 19:55:04 UTC) #14
Mark Mentovai
8 years, 4 months ago (2012-08-15 20:18:39 UTC) #15
http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store...
File rlz/mac/lib/rlz_value_store_mac.mm (right):

http://codereview.chromium.org/10823329/diff/9002/rlz/mac/lib/rlz_value_store...
rlz/mac/lib/rlz_value_store_mac.mm:282: elapsedMS += kSleepPerTryMS;
shess wrote:
> On 2012/08/15 03:24:12, Nico wrote:
> > On 2012/08/15 00:44:38, shess wrote:
> > > Also, how much contention could there be?  As implemented, someone could
get
> > > denied the lock while someone else jumps in after and claims it.  Though,
> > again,
> > > just as good as before.
> > 
> > In practice, chrome is the only app that uses rlz. (In theory, both chrome
and
> > canary could write to it, but canary is always unbranded and shouldn't use
> rlz),
> > so I think that's fine as is.
> > 
> > (Out of interest: What's a better way to do this, should there be
contention?)
> 
> I think the POSIXy way is something like:
> 
>   int end_time = time() + kTimeout;
>   do {
>     alarm(end_time - time());
>     rc = flock(fd_, LOCK_EX);
>   } while (rc == -1 && errno == EINTR && time() < end_time);
>     
> Of course, it needs to be rewritten with gettimeofday() and setitimer() to
give
> better resolution, and someone would need to verify whether this works right
> with threading.

Even without other signals, there’s no explicit guarantee that the process that
ultimately wins the exclusive lock will be the first process to request it that
blocked, so you’d be relying on an implementation detail (that incidentally is
shared by the Mac and Linux kernels).

http://codereview.chromium.org/10823329/diff/3005/rlz/mac/lib/rlz_value_store...
File rlz/mac/lib/rlz_value_store_mac.mm (right):

http://codereview.chromium.org/10823329/diff/3005/rlz/mac/lib/rlz_value_store...
rlz/mac/lib/rlz_value_store_mac.mm:301:
ignore_result(HANDLE_EINTR(close(file_lock_)));
shess wrote:
> The close() would suffice, I think.  No problem, though.

It would have, but there’s nothing wrong with the explicit flock(…, LOCK_UN)
either. Unless we’re concerned about code size. But obviously we’re not.

Powered by Google App Engine
This is Rietveld 408576698