Mercurial > public > mercurial-scm > hg-stable
diff mercurial/lock.py @ 32088:0d892d820a51 stable
lock: avoid unintentional lock acquisition at failure of readlock
Acquiring lock by vfs.makelock() and getting lock holder (aka
"locker") information by vfs.readlock() aren't atomic action.
Therefore, failure of the former doesn't ensure success of the latter.
Before this patch, lock is unintentionally acquired, if ENOENT
causes failure of vfs.readlock() while 5 times retrying, because
lock._trylock() returns to caller silently after retrying, and
lock.lock() assumes that lock._trylock() returns successfully only if
lock is acquired.
In this case, lock symlink (or file) isn't created, even though lock
is treated as acquired in memory.
To avoid this issue, this patch makes lock._trylock() raise
LockHeld(EAGAIN) at the end of it, if lock isn't acquired while
retrying.
An empty "locker" meaning "busy for frequent lock/unlock by many
processes" might appear in an abortion message, if lock acquisition
fails. Therefore, this patch also does:
- use '%r' to increase visibility of "locker", even if it is empty
- show hint message to explain what empty "locker" means
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Mon, 01 May 2017 19:59:13 +0900 |
parents | e1938d6051da |
children | 1b758105b5c7 |
line wrap: on
line diff
--- a/mercurial/lock.py Mon May 01 19:58:52 2017 +0900 +++ b/mercurial/lock.py Mon May 01 19:59:13 2017 +0900 @@ -151,6 +151,12 @@ raise error.LockUnavailable(why.errno, why.strerror, why.filename, self.desc) + if not self.held: + # use empty locker to mean "busy for frequent lock/unlock + # by many processes" + raise error.LockHeld(errno.EAGAIN, + self.vfs.join(self.f), self.desc, "") + def _readlock(self): """read lock and return its value