All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] process: Avoid bb.utils.timeout
@ 2020-08-25 23:08 Richard Purdie
  2020-08-25 23:08 ` [PATCH 2/2] utils: Drop broken timeout function Richard Purdie
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Purdie @ 2020-08-25 23:08 UTC (permalink / raw)
  To: bitbake-devel

I have a suspicion based on process traces that the flock() call is no
longer interrupted by SIGALRM and hence the timeout doesn't work. We
were relying on EINTR triggering around syscalls but python is likely
protecting us from that in modern versions.

Re-implement this code with a different mechanism which doesn't have
that potential issue.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/server/process.py | 51 +++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 24 deletions(-)

diff --git a/lib/bb/server/process.py b/lib/bb/server/process.py
index 6d936ed457..973bc45251 100644
--- a/lib/bb/server/process.py
+++ b/lib/bb/server/process.py
@@ -266,34 +266,37 @@ class ProcessServer():
         lock = None
 
         while not lock:
-            with bb.utils.timeout(3):
-                lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=True)
-                if lock:
-                    # We hold the lock so we can remove the file (hide stale pid data)
-                    # via unlockfile.
-                    bb.utils.unlockfile(lock)
-                    return
-
-                if not lock:
-                    # Some systems may not have lsof available
-                    procs = None
+            i = 0
+            lock = None
+            while not lock and i < 30:
+                time.sleep(0.1)
+                _, lock = bb.utils.lockfile(lockfile, shared=False, retry=False, block=False)
+                i += 1
+            if lock:
+                # We hold the lock so we can remove the file (hide stale pid data)
+                # via unlockfile.
+                bb.utils.unlockfile(lock)
+                return
+            if not lock:
+                # Some systems may not have lsof available
+                procs = None
+                try:
+                    procs = subprocess.check_output(["lsof", '-w', lockfile], stderr=subprocess.STDOUT)
+                except OSError as e:
+                    if e.errno != errno.ENOENT:
+                        raise
+                if procs is None:
+                    # Fall back to fuser if lsof is unavailable
                     try:
-                        procs = subprocess.check_output(["lsof", '-w', lockfile], stderr=subprocess.STDOUT)
+                        procs = subprocess.check_output(["fuser", '-v', lockfile], stderr=subprocess.STDOUT)
                     except OSError as e:
                         if e.errno != errno.ENOENT:
                             raise
-                    if procs is None:
-                        # Fall back to fuser if lsof is unavailable
-                        try:
-                            procs = subprocess.check_output(["fuser", '-v', lockfile], stderr=subprocess.STDOUT)
-                        except OSError as e:
-                            if e.errno != errno.ENOENT:
-                                raise
-
-                    msg = "Delaying shutdown due to active processes which appear to be holding bitbake.lock"
-                    if procs:
-                        msg += ":\n%s" % str(procs)
-                    print(msg)
+
+                msg = "Delaying shutdown due to active processes which appear to be holding bitbake.lock"
+                if procs:
+                    msg += ":\n%s" % str(procs)
+                print(msg)
 
     def idle_commands(self, delay, fds=None):
         nextsleep = delay
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] utils: Drop broken timeout function
  2020-08-25 23:08 [PATCH 1/2] process: Avoid bb.utils.timeout Richard Purdie
@ 2020-08-25 23:08 ` Richard Purdie
  0 siblings, 0 replies; 2+ messages in thread
From: Richard Purdie @ 2020-08-25 23:08 UTC (permalink / raw)
  To: bitbake-devel

I strongly suspect this function doesn't work with modern python so
and its unused now, drop it.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/utils.py | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/lib/bb/utils.py b/lib/bb/utils.py
index 50032e50c2..e51b8ca508 100644
--- a/lib/bb/utils.py
+++ b/lib/bb/utils.py
@@ -433,20 +433,6 @@ def fileslocked(files):
         for lock in locks:
             bb.utils.unlockfile(lock)
 
-@contextmanager
-def timeout(seconds):
-    def timeout_handler(signum, frame):
-        pass
-
-    original_handler = signal.signal(signal.SIGALRM, timeout_handler)
-
-    try:
-        signal.alarm(seconds)
-        yield
-    finally:
-        signal.alarm(0)
-        signal.signal(signal.SIGALRM, original_handler)
-
 def lockfile(name, shared=False, retry=True, block=False):
     """
     Use the specified file as a lock file, return when the lock has
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-25 23:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-25 23:08 [PATCH 1/2] process: Avoid bb.utils.timeout Richard Purdie
2020-08-25 23:08 ` [PATCH 2/2] utils: Drop broken timeout function Richard Purdie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.