Title: [266775] trunk/Tools
Revision
266775
Author
[email protected]
Date
2020-09-08 22:14:14 -0700 (Tue, 08 Sep 2020)

Log Message

kill-old-processes: Remove stale Apache2 shm segments
https://bugs.webkit.org/show_bug.cgi?id=216068

Reviewed by Alexey Proskuryakov.

Based on original patch by Diego Pino Garcia.

When Apache2 terminates abruptely, it may not free up allocated shared
memory segments.  When later Apache2 is started again, if its pid
matches the pid of orphan shm segments it fails believing there's
already an Apache2 instance running.  To avoid this situation, after
killing Apache2 we check for potential orphaned shm segments and
remove them.

If any error happens during the cleanup, log the failure and continue
the script, addressing the issue that caused the initial revert in
r266536.

* BuildSlaveSupport/kill-old-processes:
(removeOrphanShmSegments):
(orphanedShmSegmentsByUser):
(main):

Modified Paths

Diff

Modified: trunk/Tools/BuildSlaveSupport/kill-old-processes (266774 => 266775)


--- trunk/Tools/BuildSlaveSupport/kill-old-processes	2020-09-09 04:37:26 UTC (rev 266774)
+++ trunk/Tools/BuildSlaveSupport/kill-old-processes	2020-09-09 05:14:14 UTC (rev 266775)
@@ -23,7 +23,11 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+from __future__ import print_function
 import os, sys
+import getpass
+import re
+import subprocess
 
 def listAllWebKitPrograms(builddir_bin):
     foundWebKitPrograms = []
@@ -33,7 +37,43 @@
                 foundWebKitPrograms.append(file)
     return foundWebKitPrograms
 
+def removeOrphanShmSegments():
+    # When Apache2 is not gracefully shut down, it may leave orphaned shared memory segments
+    # that could cause following server instances to abort on startup.
+    try:
+        username = getpass.getuser()
+        segments = orphanedShmSegmentsByUser(username)
+        for s in segments:
+            subprocess.check_call(["ipcrm", "-m", s])
+    except Exception as e:
+        print("Error removing orphaned shared memory segments: {}".format(e), file=sys.stderr)
 
+def orphanedShmSegmentsByUser(username):
+    ret = []
+    output = subprocess.check_output(["ipcs", "-m"])
+    lines = output.split('\n')
+    if len(lines) < 3:
+        return []
+
+    headers = [header.strip() for header in lines[2].split()]
+    wanted_headers = ['nattch', 'owner', 'shmid']
+
+    if any(h not in headers for h in wanted_headers):
+        raise RuntimeError("Failed to find required nattch, owner and shmid cols in ipcs output")
+    nattch_idx = headers.index('nattch')
+    owner_idx = headers.index('owner')
+    shmid_idx = headers.index('shmid')
+
+    for line in lines[3:]:
+        line = line.strip()
+        tokens = [x.strip() for x in line.split()]
+        try:
+            if tokens[nattch_idx] == '0' and tokens[owner_idx] == username:
+                ret.append(tokens[shmid_idx])
+        except IndexError:
+            continue
+    return ret
+
 def main(user=None):
     tasksToKillWin = [
         "cl.exe",
@@ -141,6 +181,7 @@
         for task in tasksToKill + taskToKillUnix + listAllWebKitPrograms(builddir_bin):
             os.system("killall -9 -v " + task)
         os.system("ps aux | grep -P '.+/python .+(run_webkit_tests|run-webkit-tests|mod_pywebsocket)' | grep -v grep | awk '{print $2}' | xargs kill")
+        removeOrphanShmSegments()
     else:
         sys.exit()
         # FIXME: Should we return an exit code based on how the kills went?

Modified: trunk/Tools/ChangeLog (266774 => 266775)


--- trunk/Tools/ChangeLog	2020-09-09 04:37:26 UTC (rev 266774)
+++ trunk/Tools/ChangeLog	2020-09-09 05:14:14 UTC (rev 266775)
@@ -1,3 +1,28 @@
+2020-09-08  Lauro Moura  <[email protected]>
+
+        kill-old-processes: Remove stale Apache2 shm segments
+        https://bugs.webkit.org/show_bug.cgi?id=216068
+
+        Reviewed by Alexey Proskuryakov.
+
+        Based on original patch by Diego Pino Garcia.
+
+        When Apache2 terminates abruptely, it may not free up allocated shared
+        memory segments.  When later Apache2 is started again, if its pid
+        matches the pid of orphan shm segments it fails believing there's
+        already an Apache2 instance running.  To avoid this situation, after
+        killing Apache2 we check for potential orphaned shm segments and
+        remove them.
+
+        If any error happens during the cleanup, log the failure and continue
+        the script, addressing the issue that caused the initial revert in
+        r266536.
+
+        * BuildSlaveSupport/kill-old-processes:
+        (removeOrphanShmSegments):
+        (orphanedShmSegmentsByUser):
+        (main):
+
 2020-09-08  Fujii Hironori  <[email protected]>
 
         [WinCairo] TestWTF.WTF.UniqueRef is crashing in Debug builds
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to