comparison 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
comparison
equal deleted inserted replaced
32087:e1938d6051da 32088:0d892d820a51
148 self.vfs.join(self.f), self.desc, 148 self.vfs.join(self.f), self.desc,
149 locker) 149 locker)
150 else: 150 else:
151 raise error.LockUnavailable(why.errno, why.strerror, 151 raise error.LockUnavailable(why.errno, why.strerror,
152 why.filename, self.desc) 152 why.filename, self.desc)
153
154 if not self.held:
155 # use empty locker to mean "busy for frequent lock/unlock
156 # by many processes"
157 raise error.LockHeld(errno.EAGAIN,
158 self.vfs.join(self.f), self.desc, "")
153 159
154 def _readlock(self): 160 def _readlock(self):
155 """read lock and return its value 161 """read lock and return its value
156 162
157 Returns None if no lock exists, pid for old-style locks, and host:pid 163 Returns None if no lock exists, pid for old-style locks, and host:pid