diff options
author | Chetan Mishra <chetan.s115@gmail.com> | 2017-04-09 10:02:12 -0400 |
---|---|---|
committer | Tim Burke <tim.burke@gmail.com> | 2023-04-28 08:57:35 -0700 |
commit | 84b995f275c42795b2193a92eaef0329f68a1f20 (patch) | |
tree | fd00863191987a7eab0d8046714675f6f22a1cdc /swift | |
parent | 3b89fbebd9adcf2b2247f9923f1e76491972a306 (diff) | |
download | swift-84b995f275c42795b2193a92eaef0329f68a1f20.tar.gz |
Don't monkey patch logging on import
Previously swift.common.utils monkey patched logging.thread,
logging.threading, and logging._lock upon import with eventlet
threading modules, but that is no longer reasonable or necessary.
With py3, the existing logging._lock is not patched by eventlet,
unless the logging module is reloaded. The existing lock is not
tracked by the gc so would not be found by eventlet's
green_existing_locks().
Instead we group all monkey patching into utils function and apply
patching consistently across daemons and WSGI servers.
Co-Authored-By: Clay Gerrard <clay.gerrard@gmail.com>
Co-Authored-By: Alistair Coles <alistairncoles@gmail.com>
Closes-Bug: #1380815
Change-Id: I6f35ad41414898fb7dc5da422f524eb52ff2940f
Diffstat (limited to 'swift')
-rw-r--r-- | swift/common/daemon.py | 6 | ||||
-rw-r--r-- | swift/common/utils/__init__.py | 30 | ||||
-rw-r--r-- | swift/common/wsgi.py | 2 |
3 files changed, 25 insertions, 13 deletions
diff --git a/swift/common/daemon.py b/swift/common/daemon.py index 773ca9424..300710e98 100644 --- a/swift/common/daemon.py +++ b/swift/common/daemon.py @@ -20,8 +20,8 @@ import time import signal from re import sub +import eventlet import eventlet.debug -from eventlet.hubs import use_hub from swift.common import utils @@ -281,7 +281,9 @@ def run_daemon(klass, conf_file, section_name='', once=False, **kwargs): # and results in an exit code of 1. sys.exit(e) - use_hub(utils.get_hub()) + # patch eventlet/logging early + utils.monkey_patch() + eventlet.hubs.use_hub(utils.get_hub()) # once on command line (i.e. daemonize=false) will over-ride config once = once or not utils.config_true_value(conf.get('daemonize', 'true')) diff --git a/swift/common/utils/__init__.py b/swift/common/utils/__init__.py index 16dc58807..cdaa0b807 100644 --- a/swift/common/utils/__init__.py +++ b/swift/common/utils/__init__.py @@ -119,16 +119,10 @@ from swift.common.utils.timestamp import ( # noqa normalize_delete_at_timestamp, ) -# logging doesn't import patched as cleanly as one would like from logging.handlers import SysLogHandler import logging -logging.thread = eventlet.green.thread -logging.threading = eventlet.green.threading -logging._lock = logging.threading.RLock() -# setup notice level logging + NOTICE = 25 -logging.addLevelName(NOTICE, 'NOTICE') -SysLogHandler.priority_map['NOTICE'] = 'notice' # Used by hash_path to offer a bit more security when generating hashes for # paths. It simply appends this value to all paths; guessing the hash a path @@ -442,6 +436,17 @@ def config_read_prefixed_options(conf, prefix_name, defaults): return params +def logging_monkey_patch(): + # explicitly patch the logging lock + logging._lock = logging.threading.RLock() + # setup notice level logging + logging.addLevelName(NOTICE, 'NOTICE') + SysLogHandler.priority_map['NOTICE'] = 'notice' + # Trying to log threads while monkey-patched can lead to deadlocks; see + # https://bugs.launchpad.net/swift/+bug/1895739 + logging.logThreads = 0 + + def eventlet_monkey_patch(): """ Install the appropriate Eventlet monkey patches. @@ -452,9 +457,14 @@ def eventlet_monkey_patch(): # if thread is monkey-patched. eventlet.patcher.monkey_patch(all=False, socket=True, select=True, thread=True) - # Trying to log threads while monkey-patched can lead to deadlocks; see - # https://bugs.launchpad.net/swift/+bug/1895739 - logging.logThreads = 0 + + +def monkey_patch(): + """ + Apply all swift monkey patching consistently in one place. + """ + eventlet_monkey_patch() + logging_monkey_patch() def validate_configuration(): diff --git a/swift/common/wsgi.py b/swift/common/wsgi.py index 7c39a89e2..99dc4c203 100644 --- a/swift/common/wsgi.py +++ b/swift/common/wsgi.py @@ -838,7 +838,7 @@ def run_wsgi(conf_path, app_section, *args, **kwargs): return 1 # patch event before loadapp - utils.eventlet_monkey_patch() + utils.monkey_patch() # Ensure the configuration and application can be loaded before proceeding. global_conf = {'log_name': log_name} |