From 0ea37b36a11fc556f4e7ac9c56fde33e150a75ed Mon Sep 17 00:00:00 2001 From: Don Penney Date: Mon, 11 Mar 2019 10:52:00 -0400 Subject: [PATCH] Trigger garbage collection to free WSGI resources The wsgiref.simple_server is used by patching for handling API requests. When uploading files, the server opens a file handle for the temporary resource, but does not close it. Instead, it's left to periodic garbage collection to free the resources. Until garbage collection, however, this means disk space is still in use for the deleted temporary file, as the handle is left open. This update adds a call to gc.collect() after the call to simple_server.handle_request() to immediately free all unused resources. Change-Id: Ie39213dad540448cede46cc8e580d31582419dcc Closes-Bug: 1797977 Signed-off-by: Don Penney --- .../cgcs-patch/cgcs_patch/patch_controller.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py b/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py index eb021958..4cf48d46 100644 --- a/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py +++ b/cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2014-2017 Wind River Systems, Inc. +Copyright (c) 2014-2019 Wind River Systems, Inc. SPDX-License-Identifier: Apache-2.0 @@ -14,6 +14,7 @@ import subprocess from six.moves import configparser import rpm import os +import gc from rpmUtils.miscutils import stringToVersion # pylint: disable=import-error @@ -2179,6 +2180,11 @@ class PatchControllerApiThread(threading.Thread): global keep_running while keep_running: self.wsgi.handle_request() + + # Call garbage collect after wsgi request is handled, + # to ensure any open file handles are closed in the case + # of an upload. + gc.collect() except Exception: # Log all exceptions LOG.exception("Error occurred during request processing") @@ -2230,6 +2236,11 @@ class PatchControllerAuthApiThread(threading.Thread): global keep_running while keep_running: self.wsgi.handle_request() + + # Call garbage collect after wsgi request is handled, + # to ensure any open file handles are closed in the case + # of an upload. + gc.collect() except Exception: # Log all exceptions LOG.exception("Authorized API failure: Error occurred during request processing")