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 <don.penney@windriver.com>
This commit is contained in:
parent
f4f7043259
commit
0ea37b36a1
@ -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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user