Issue132

Title hg should revalidate its data after locking the repo
Priority urgent Status done-cbb
Superseder Nosy List ThomasAH, alexis, bos, junkblocker, kupfer, mpm, psimons, tonfa
Assigned To mpm Topics

Created on 2006-02-18.01:00:04 by alexis, last changed 2008-02-15.10:12:57 by ThomasAH.

Files
File name Uploaded Type Edit Remove
bug-clone-pull.sh alexis, 2006-02-18.22:26:48 application/x-shellscript
bug-pull-pull.sh alexis, 2006-02-18.22:28:30 application/x-shellscript
race.diff tonfa, 2006-02-20.00:35:24 text/plain
wlock_race.diff tonfa, 2006-02-24.04:25:46 text/plain
Messages
msg3412 (view) Author: mpm Date: 2007-07-02.21:31:04
Or perhaps we can mark the dirstate entries invalid.
msg3250 (view) Author: mpm Date: 2007-06-22.20:37:08
Aside from commit being inherently racy, I think the fixable parts of this have
been addressed.
msg3041 (view) Author: ThomasAH Date: 2007-05-01.16:27:02
See also issue552 (Errors in test-clone-pull-corruption)
msg2327 (view) Author: shap Date: 2006-11-02.19:02:57
Observation: in the presence of hooks that can mutate the local filesystem,
there is a general problem that the "order of operation" for commit processing
needs to be explicitly defined. There was another bug (can't find it at the
moment) wherein a file being committed was modified by a commit script.

The main point is that anything of the form "read after write after read" is bad
news, and the only way to resolve these in general is to have a well defined and
documented processing model for handling the workspace.
msg1110 (view) Author: tonfa Date: 2006-05-02.12:51:07
On 3/31/06, Alexis S. L. Carvalho <mercurial-bugs@selenic.com> wrote:
>
> Two questions about the changes to the commit function:
>
> - With these changes, the precommit hook will run while holding the wlock.
>   Is that a problem?

I don't think it matters, the user probably don't want the working
copy to be modified (eg update/adding/removing/...) in the precommit
hook.
>
> - Should the wlock be passed to the changes function?
>
It should if possible, I'll correct it if the patch is ok.

thanks,

Benoit
msg879 (view) Author: alexis Date: 2006-03-30.23:16:22
Two questions about the changes to the commit function:

- With these changes, the precommit hook will run while holding the wlock.
  Is that a problem?

- Should the wlock be passed to the changes function?

Other than that, it looks ok to me.
msg850 (view) Author: tonfa Date: 2006-03-28.16:00:13
On 3/28/06, Bryan O'Sullivan <mercurial-bugs@selenic.com> wrote:
>
> Which patch?  :-)  There are 4 patches attached to the bug, and I don't know
> which one you're talking about.

race.diff was already applied, I am talking about wlock_race.diff

Benoit
msg848 (view) Author: bos Date: 2006-03-28.15:35:23
Which patch?  :-)  There are 4 patches attached to the bug, and I don't know
which one you're talking about.
msg839 (view) Author: tonfa Date: 2006-03-28.03:35:27
back to this, is something missing in the patch ?
msg777 (view) Author: ThomasAH Date: 2006-03-21.10:10:40
set to in-progress, as wlock_race.diff isn't applied yet.
msg558 (view) Author: bos Date: 2006-02-24.05:48:54
There's no harm in checking all of mtime, ctime and size.
msg557 (view) Author: tonfa Date: 2006-02-24.04:25:46
If the size is the same, then mtime/ctime are probably the same
(except when stripping, but we don't care for that case).

A patch is attached for the possible race in commit/update/...
msg535 (view) Author: mpm Date: 2006-02-22.07:00:06
On Wed, Feb 22, 2006 at 06:45:18AM +0000, Thomas Arendsen Hein wrote:
> 
> Thomas Arendsen Hein <thomas@intevation.de> added the comment:
> 
> Looks good and works fine.
> 
> Pushed to http://hg.intevation.org/mercurial/tah with test cases added.
> Should I push to crew?

Yes.
msg534 (view) Author: ThomasAH Date: 2006-02-22.06:45:16
Looks good and works fine.

Pushed to http://hg.intevation.org/mercurial/tah with test cases added.
Should I push to crew?
msg519 (view) Author: tonfa Date: 2006-02-20.00:35:24
updated patch against tip
msg518 (view) Author: tonfa Date: 2006-02-19.17:44:27
Proposed fix attached.
msg514 (view) Author: alexis Date: 2006-02-18.22:28:30
And here's a script to reproduce the "pull+pull" corruption.

The same comments from the last message apply.
msg513 (view) Author: alexis Date: 2006-02-18.22:26:48
bos has suggested using hooks to easily reproduce the situations that I
described.

Here's a script to reproduces the "clone+pull" corruption.  You can specify
an alternative hg command to use through the HG environment variable.

hg verify reports a different corruption, but it's still avoidable by 
rereading the manifest and changelog after locking the repo in the pull
method.
msg512 (view) Author: alexis Date: 2006-02-18.17:23:27
Note that this is not just an issue with commits or rollbacks.  Here's a
way to corrupt the repo with two (successful!) pulls:

Add something like this to localrepository.pull after locking the repo,
just to make the race very easy to exploit:

        import time
	time.sleep(5)

Then create one repo with a long history and another one with a shorter
(but different) history.  And then pull them both into a third
repository.  Boom.

hg init source1
cd source1
touch foo
hg add foo
for i in $(seq 10); do echo $1 >> foo; hg ci -m $i; done
cd ..
hg clone -r 0 source1 source2
cd source2
echo a >> foo
hg ci -m a
cd ..
hg init corrupted
cd corrupted
hg pull ../source1 & sleep 1; hg pull ../source2

Both pulls think there was no problem, but:
$ hg verify
checking changesets
changelog data length off by 854 bytes
Segmentation fault

Rereading the manifest and the changelog after locking the repo fixes
this.
msg507 (view) Author: ThomasAH Date: 2006-02-18.05:35:09
The planned reordering of commit would help here a little bit, but there still
will be a race condition then if a different error causes a rollback.
msg506 (view) Author: bos Date: 2006-02-18.05:30:01
Nice piece of detective work.  I'm bumping this to urgent, since it can corrupt
the repository.
msg504 (view) Author: alexis Date: 2006-02-18.00:59:59
A while ago somebody mentioned on IRC that hg pull would corrupt the
repo if it was started while a (soon to be aborted) commit was running
(more details on how to reproduce this below).

After poking it a bit, I think this happens because the manifest is read
in localrepository.__init__ (when the file has already been changed for
the commit), but when we actually get to use the manifest, the aborted
commit has already rolledback the repo.

To try to confirm this, I've tried to reread the manifest after locking
the repo in the pull method, and this does indeed fix this particular
issue.  This is of course only a quick hack, since there are probably a
few other places that would need some fixing.

How to reproduce it:

# create 2 repos, such that one of them can pull from the other
hg init a
cd a
touch foo
hg add foo
hg ci -m 'add foo'
hg clone . ../b
echo >> foo
hg ci -m 'change foo'
cd ..

# go into repo b and start a new commit
cd b
touch bar
hg add bar
hg ci
# do not close your editor

# in another shell, do an hg pull
cd b
hg pull ../a
# this will block, waiting for the lock
# go back to the editor and quit it without saving, to abort the commit.
# it will abort the transaction and rollback everything, without
# problems, but the hg pull will print something like:
pulling from ../a
waiting for lock held by 5592
searching for changes
adding changesets
adding manifests
abort: integrity check failed on 00manifest.d:1!
transaction abort!
rollback completed

# the output of hg verify afterwards
checking changesets
checking manifests
manifest data length off by 103 bytes
crosschecking files in changesets and manifests
checking files
1 files, 1 changesets, 1 total revisions
1 integrity errors encountered!
History
Date User Action Args
2008-02-15 10:12:57ThomasAHsettopic: - release
nosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
2008-02-11 12:10:34djcsetstatus: chatting -> done-cbb
nosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
2007-12-08 02:38:32mpmsetstatus: in-progress -> chatting
nosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
2007-07-02 22:14:00mpmsettopic: + release
nosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
2007-07-02 21:32:33mpmsetnosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
assignedto: tonfa -> mpm
2007-07-02 21:31:05mpmsetstatus: resolved -> in-progress
nosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
messages: + msg3412
2007-06-22 20:37:08mpmsetstatus: in-progress -> resolved
nosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
messages: + msg3250
2007-06-22 20:30:43mpmsetnosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
superseder: - Rollback can race with pull
2007-06-22 20:30:17mpmsetnosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
superseder: + Rollback can race with pull
2007-05-01 16:27:02ThomasAHsetnosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer, psimons
messages: + msg3041
2006-11-05 18:20:17psimonssetnosy: + psimons
2006-11-02 19:02:57shapsetnosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer
messages: + msg2327
2006-05-02 12:51:22tonfasetnosy: mpm, bos, ThomasAH, tonfa, alexis, junkblocker, kupfer
messages: + msg1110
2006-04-15 02:21:47junkblockersetnosy: + junkblocker
2006-04-05 06:15:00Angelsetnosy: mpm, bos, ThomasAH, tonfa, alexis, kupfer
messages: - msg555
2006-03-30 23:16:26alexissetnosy: mpm, bos, ThomasAH, tonfa, alexis, kupfer
messages: + msg879
2006-03-29 22:35:42kupfersetnosy: + kupfer
2006-03-28 16:00:13tonfasetnosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg850
2006-03-28 15:35:23bossetnosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg848
2006-03-28 03:35:29tonfasetnosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg839
2006-03-21 10:10:41ThomasAHsetstatus: testing -> in-progress
nosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg777
2006-02-24 05:48:55bossetnosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg558
2006-02-24 04:25:50tonfasetfiles: + wlock_race.diff
nosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg557
2006-02-24 03:24:08alexissetnosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg555
2006-02-22 07:00:10mpmsetnosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg535
2006-02-22 06:45:18ThomasAHsetstatus: in-progress -> testing
nosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg534
2006-02-20 00:35:59tonfasetfiles: - race.diff
nosy: mpm, bos, ThomasAH, tonfa, alexis
2006-02-20 00:35:27tonfasetfiles: + race.diff
nosy: mpm, bos, ThomasAH, tonfa, alexis
messages: + msg519
2006-02-19 17:44:30tonfasetstatus: chatting -> in-progress
files: + race.diff
assignedto: tonfa
messages: + msg518
nosy: + tonfa
2006-02-18 22:28:30alexissetfiles: + bug-pull-pull.sh
nosy: mpm, bos, ThomasAH, alexis
messages: + msg514
2006-02-18 22:26:54alexissetfiles: + bug-clone-pull.sh
nosy: mpm, bos, ThomasAH, alexis
messages: + msg513
2006-02-18 17:23:30alexissetnosy: mpm, bos, ThomasAH, alexis
messages: + msg512
2006-02-18 05:35:09ThomasAHsetnosy: + ThomasAH, mpm
messages: + msg507
2006-02-18 05:30:05bossetpriority: bug -> urgent
status: unread -> chatting
messages: + msg506
nosy: + bos
2006-02-18 01:00:04alexiscreate