counter_tick_core: don't lock if parallel-install
authorZac Medico <zmedico@gentoo.org>
Sat, 14 May 2011 23:53:35 +0000 (16:53 -0700)
committerZac Medico <zmedico@gentoo.org>
Sat, 14 May 2011 23:53:35 +0000 (16:53 -0700)
Hopefully this avoids the following exception:

  File "/usr/lib/portage/pym/portage/locks.py", line 138, in lockfile
    fcntl.lockf(myfd, fcntl.LOCK_EX)
IOError: [Errno 35] Resource deadlock avoided

pym/portage/dbapi/vartree.py

index fca590a0b1d307491c25a658cc617e355e1be997..802253afc173a33f67102d6a63c493c3337190ea 100644 (file)
@@ -789,7 +789,15 @@ class vardbapi(dbapi):
                """
                myroot = None
                mycpv = None
-               self.lock()
+               locked_vdb = False
+               if "parallel-install" not in self.settings.features:
+                       # If parallel-install is enabled, it's unsafe to
+                       # lock the vdb here since the portage.locks module
+                       # does not behave as desired if we try to lock the
+                       # same file multiple times concurrently from the
+                       # same process.
+                       self.lock()
+                       locked_vdb = True
                try:
                        counter = self.get_counter_tick_core() - 1
                        if self._cached_counter != counter:
@@ -803,7 +811,8 @@ class vardbapi(dbapi):
                                        write_atomic(self._counter_path, str(counter))
                                self._cached_counter = counter
                finally:
-                       self.unlock()
+                       if locked_vdb:
+                               self.unlock()
 
                return counter