support/scripts/pkg-stats: clear multiprocessing pools after use
authorTitouan Christophe <titouan.christophe@railnova.eu>
Sun, 1 Mar 2020 21:25:28 +0000 (22:25 +0100)
committerThomas Petazzoni <thomas.petazzoni@bootlin.com>
Sat, 7 Mar 2020 14:59:08 +0000 (15:59 +0100)
During the CVE checking phase, we can still see a huge amount of
Python processes (actually 128) running on the host, even though
the CVE step is entirely ran in the main thread.

These are actually the worker processes spawned to check for the
packages URL statuses and the latest versions from release-monitoring.
This is because of an issue in Python's multiprocessing implementation:
https://bugs.python.org/issue34172

The problem was already there before the CVE matching step was
introduced, but because pkg-stat was terminating right after the
release-monitoring step, it went unnoticed.

Also, do not hold a reference to the multiprocessing pool from
the Package class, as this is not needed.

Signed-off-by: Titouan Christophe <titouan.christophe@railnova.eu>
Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
support/scripts/pkg-stats

index e414ec50f2298ed7ebbb452c0f82f94b782dc555..8a67e509e11f4636d2b8e7e8549edcf86e24c014 100755 (executable)
@@ -402,11 +402,13 @@ def check_url_status_worker(url, url_status):
 
 
 def check_package_urls(packages):
-    Package.pool = Pool(processes=64)
+    pool = Pool(processes=64)
     for pkg in packages:
-        pkg.url_worker = pkg.pool.apply_async(check_url_status_worker, (pkg.url, pkg.url_status))
+        pkg.url_worker = pool.apply_async(check_url_status_worker, (pkg.url, pkg.url_status))
     for pkg in packages:
         pkg.url_status = pkg.url_worker.get(timeout=3600)
+        del pkg.url_worker
+    pool.terminate()
 
 
 def release_monitoring_get_latest_version_by_distro(pool, name):
@@ -479,6 +481,7 @@ def check_package_latest_version(packages):
     results = worker_pool.map(check_package_latest_version_worker, (pkg.name for pkg in packages))
     for pkg, r in zip(packages, results):
         pkg.latest_version = r
+    worker_pool.terminate()
     del http_pool