Title: [266507] trunk/Tools
Revision
266507
Author
dp...@igalia.com
Date
2020-09-03 01:07:48 -0700 (Thu, 03 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.

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 conflicting shm segments and
remove them.

* BuildSlaveSupport/kill-old-processes:
(listAllWebKitPrograms):
(removeOrphanShmSegmentsOf):
(removeShmSegments):
(removeShmSegment):
(cmd):
(allShmSegments):
(main):

Modified Paths

Diff

Modified: trunk/Tools/BuildSlaveSupport/kill-old-processes (266506 => 266507)


--- trunk/Tools/BuildSlaveSupport/kill-old-processes	2020-09-03 07:48:56 UTC (rev 266506)
+++ trunk/Tools/BuildSlaveSupport/kill-old-processes	2020-09-03 08:07:48 UTC (rev 266507)
@@ -24,6 +24,8 @@
 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 import os, sys
+import subprocess
+import re
 
 def listAllWebKitPrograms(builddir_bin):
     foundWebKitPrograms = []
@@ -33,7 +35,45 @@
                 foundWebKitPrograms.append(file)
     return foundWebKitPrograms
 
+def removeOrphanShmSegmentsOf(task):
+    pid = futurePidOf(task)
+    segments = filter(lambda s: s['owner'] == os.environ.get("USER"), allShmSegments())
+    segments = filter(lambda s: s['cpid'] == pid, segments)
+    removeShmSegments(segments)
 
+def removeShmSegments(l):
+    for each in l:
+        removeShmSegment(each)
+
+def removeShmSegment(s):
+    subprocess.check_call(cmd("ipcrm -m {}".format(s['shmid'])))
+
+def cmd(string):
+    return re.split(r'\s+', string)
+    
+def futurePidOf(task):
+    devnull = open(os.devnull, 'w')
+    ps = subprocess.Popen(task, stderr=subprocess.STDOUT, stdout=devnull)
+    pid = ps.pid
+    ps.wait()
+    try:
+        ps.terminate()
+    except OSError:
+        pass
+    return pid
+
+def allShmSegments():
+    ret = []
+    output = subprocess.check_output(cmd("ipcs -m -p"))
+    if len(output) > 0:
+        lines = output.split("\n")
+        for line in lines[3:]:
+            line = line.strip()
+            if len(line) == 0: continue
+            shmid, owner, cpid, lpid = re.split(r'\s+', line)
+            ret.append({'shmid': int(shmid), 'owner': owner, 'cpid': int(cpid), 'lpid': int(lpid)})
+    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")
+        removeOrphanShmSegmentsOf("apache2")
     else:
         sys.exit()
         # FIXME: Should we return an exit code based on how the kills went?

Modified: trunk/Tools/ChangeLog (266506 => 266507)


--- trunk/Tools/ChangeLog	2020-09-03 07:48:56 UTC (rev 266506)
+++ trunk/Tools/ChangeLog	2020-09-03 08:07:48 UTC (rev 266507)
@@ -1,3 +1,26 @@
+2020-09-03  Diego Pino Garcia  <dp...@igalia.com>
+
+        kill-old-processes: Remove stale Apache2 shm segments
+        https://bugs.webkit.org/show_bug.cgi?id=216068
+
+        Reviewed by Alexey Proskuryakov.
+
+        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 conflicting shm segments and
+        remove them.
+
+        * BuildSlaveSupport/kill-old-processes:
+        (listAllWebKitPrograms):
+        (removeOrphanShmSegmentsOf):
+        (removeShmSegments):
+        (removeShmSegment):
+        (cmd):
+        (allShmSegments):
+        (main):
+
 2020-09-03  Ryosuke Niwa  <rn...@webkit.org>
 
         Static assert the return type of compactMap
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to