annotate tests/test-record.t @ 43709:039fbd14d4e2

lock: fix race in lock-breaking code With low frequency, I see hg pulls fail with output like: abort: no such file or directory: .hg/store/lock I think what happens is, in lock.py, in: def _testlock(self, locker): if not self._lockshouldbebroken(locker): return locker # if locker dead, break lock. must do this with another lock # held, or can race and break valid lock. try: with lock(self.vfs, self.f + b'.break', timeout=0): self.vfs.unlink(self.f) except error.LockError: return locker if a lock is breakable on disk, and two hg processes concurrently get to the "if locker dead" comment, a possible interleaving is: process1 finishes executing the function and then process2 finishes executing the function. If that happens, process2 will either get ENOENT in self.vfs.unlink (resulting in the spurious failure above), or break a valid lock and potentially cause repository corruption. The fix is simple enough: make sure the lock is breakable _inside_ the critical section, because only then can we know that no other process can invalidate our knowledge on the lock on disk. I don't think there are tests for this. I've tested this manually with: diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -351,6 +351,8 @@ class lock(object): if not self._lockshouldbebroken(locker): return locker + import random + time.sleep(1. + random.random()) # if locker dead, break lock. must do this with another lock # held, or can race and break valid lock. try: @@ -358,6 +360,7 @@ class lock(object): self.vfs.unlink(self.f) except error.LockError: return locker + time.sleep(1) def testlock(self): """return id of locker if lock is valid, else None. and I see this change of behavior before/after this commit: $ $hg init repo $ cd repo $ ln -s $HOSTNAME/effffffc:987654321 .hg/wlock $ touch a $ $hg commit -Am_ & $hg commit -Am _; wait -abort: No such file or directory: '/tmp/repo/.hg/wlock' adding a +warning: ignoring unknown working parent 679a8959a8ca! +nothing changed Differential Revision: https://phab.mercurial-scm.org/D7199
author Valentin Gatien-Baron <valentin.gatienbaron@gmail.com>
date Mon, 18 Nov 2019 20:10:38 -0800
parents db72f9f6580e
children 8d72e29ad1e0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12328
b63f6422d2a7 tests: fix a bunch of pointless #s in unified tests
Matt Mackall <mpm@selenic.com>
parents: 12316
diff changeset
1 Set up a repo
5037
b2607267236d Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
2
23172
e955549cd045 tests: write hgrc of more than two lines by using shell heredoc
Yuya Nishihara <yuya@tcha.org>
parents: 23054
diff changeset
3 $ cat <<EOF >> $HGRCPATH
e955549cd045 tests: write hgrc of more than two lines by using shell heredoc
Yuya Nishihara <yuya@tcha.org>
parents: 23054
diff changeset
4 > [ui]
e955549cd045 tests: write hgrc of more than two lines by using shell heredoc
Yuya Nishihara <yuya@tcha.org>
parents: 23054
diff changeset
5 > interactive = true
e955549cd045 tests: write hgrc of more than two lines by using shell heredoc
Yuya Nishihara <yuya@tcha.org>
parents: 23054
diff changeset
6 > [extensions]
e955549cd045 tests: write hgrc of more than two lines by using shell heredoc
Yuya Nishihara <yuya@tcha.org>
parents: 23054
diff changeset
7 > record =
e955549cd045 tests: write hgrc of more than two lines by using shell heredoc
Yuya Nishihara <yuya@tcha.org>
parents: 23054
diff changeset
8 > EOF
5037
b2607267236d Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
9
12074
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
10 $ hg init a
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
11 $ cd a
5037
b2607267236d Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
12
24308
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
13 Record help
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
14
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
15 $ hg record -h
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
16 hg record [OPTION]... [FILE]...
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
17
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
18 interactively select changes to commit
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
19
27729
58f8b29c37ff minirst: change hgrole to use single quotes
timeless <timeless@mozdev.org>
parents: 25304
diff changeset
20 If a list of files is omitted, all changes reported by 'hg status' will be
24308
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
21 candidates for recording.
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
22
27729
58f8b29c37ff minirst: change hgrole to use single quotes
timeless <timeless@mozdev.org>
parents: 25304
diff changeset
23 See 'hg help dates' for a list of formats valid for -d/--date.
24308
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
24
31065
7074589cf22a record: update help to describe ui.interface
eloimorlaas <eloimorlaas@fb.com>
parents: 30158
diff changeset
25 If using the text interface (see 'hg help config'), you will be prompted
7074589cf22a record: update help to describe ui.interface
eloimorlaas <eloimorlaas@fb.com>
parents: 30158
diff changeset
26 for whether to record changes to each modified file, and for files with
7074589cf22a record: update help to describe ui.interface
eloimorlaas <eloimorlaas@fb.com>
parents: 30158
diff changeset
27 multiple changes, for each change to use. For each query, the following
7074589cf22a record: update help to describe ui.interface
eloimorlaas <eloimorlaas@fb.com>
parents: 30158
diff changeset
28 responses are possible:
24308
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
29
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
30 y - record this change
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
31 n - skip this change
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
32 e - edit this change manually
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
33
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
34 s - skip remaining changes to this file
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
35 f - record remaining changes to this file
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
36
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
37 d - done, skip remaining changes and files
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
38 a - record all changes to all remaining files
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
39 q - quit, recording no changes
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
40
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
41 ? - display help
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
42
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
43 This command is not available when committing a merge.
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
44
29974
7109d5ddeb0c help: use single quotes in use warning
timeless <timeless@mozdev.org>
parents: 28697
diff changeset
45 (use 'hg help -e record' to show help for the record extension)
28697
d001d6d27570 record: deprecate the extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 27729
diff changeset
46
24308
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
47 options ([+] can be repeated):
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
48
30152
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
49 -A --addremove mark new/missing files as added/removed before
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
50 committing
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
51 --close-branch mark a branch head as closed
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
52 --amend amend the parent of the working directory
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
53 -s --secret use the secret phase for committing
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
54 -e --edit invoke editor on commit messages
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
55 -I --include PATTERN [+] include names matching the given patterns
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
56 -X --exclude PATTERN [+] exclude names matching the given patterns
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
57 -m --message TEXT use text as commit message
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
58 -l --logfile FILE read commit message from file
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
59 -d --date DATE record the specified date as commit date
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
60 -u --user USER record the specified user as committer
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
61 -S --subrepos recurse into subrepositories
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
62 -w --ignore-all-space ignore white space when comparing lines
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
63 -b --ignore-space-change ignore changes in the amount of white space
d65e246100ed help: backout f3c4edfd35e1 (mark boolean flags with [no-] in help) for now
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 30024
diff changeset
64 -B --ignore-blank-lines ignore changes whose lines are all blank
34013
da07367d683b mdiff: add a --ignore-space-at-eol option
David Soria Parra <davidsp@fb.com>
parents: 31065
diff changeset
65 -Z --ignore-space-at-eol ignore changes in whitespace at EOL
24308
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
66
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
67 (some details hidden, use --verbose to show complete help)
1725843a7644 record: remove duplicated tests
Laurent Charignon <lcharignon@fb.com>
parents: 24235
diff changeset
68
12074
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
69 Select no files
5037
b2607267236d Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
70
12074
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
71 $ touch empty-rw
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
72 $ hg add empty-rw
5037
b2607267236d Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
73
12074
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
74 $ hg record empty-rw<<EOF
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
75 > n
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
76 > EOF
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
77 diff --git a/empty-rw b/empty-rw
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
78 new file mode 100644
42071
db72f9f6580e interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34013
diff changeset
79 abort: empty commit message
db72f9f6580e interactive: do not prompt about files given in command line
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 34013
diff changeset
80 [255]
12074
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
81
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
82 $ hg tip -p
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
83 changeset: -1:000000000000
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
84 tag: tip
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
85 user:
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
86 date: Thu Jan 01 00:00:00 1970 +0000
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
87
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
88
35c143e85b1b tests: unify test-record
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents: 11238
diff changeset
89
5037
b2607267236d Add record extension, giving darcs-like interactive hunk picking
Bryan O'Sullivan <bos@serpentine.com>
parents:
diff changeset
90