summary refs log tree commit diff
path: root/synapse/util/logcontext.py
diff options
context:
space:
mode:
authorhera <matrix@template.upcloud.com>2018-08-21 19:12:14 +0000
committerhera <matrix@template.upcloud.com>2018-08-21 19:12:14 +0000
commitd1065e6f512447e6ba9dc4beddf26695880023e1 (patch)
tree4c54a1e7e9f62bda2689bd47f69d65708fd3b7c8 /synapse/util/logcontext.py
parentMerge branch 'develop' of github.com:matrix-org/synapse into matrix-org-hotfixes (diff)
parentchangelog (diff)
downloadsynapse-d1065e6f512447e6ba9dc4beddf26695880023e1.tar.xz
Merge tag 'v0.33.3rc2' into matrix-org-hotfixes
Bugfixes
--------

- Fix bug in v0.33.3rc1 which caused infinite loops and OOMs
([\#3723](https://github.com/matrix-org/synapse/issues/3723))
Diffstat (limited to 'synapse/util/logcontext.py')
-rw-r--r--synapse/util/logcontext.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py

index 07e83fadda..a0c2d37610 100644 --- a/synapse/util/logcontext.py +++ b/synapse/util/logcontext.py
@@ -385,7 +385,13 @@ class LoggingContextFilter(logging.Filter): context = LoggingContext.current_context() for key, value in self.defaults.items(): setattr(record, key, value) - context.copy_to(record) + + # context should never be None, but if it somehow ends up being, then + # we end up in a death spiral of infinite loops, so let's check, for + # robustness' sake. + if context is not None: + context.copy_to(record) + return True @@ -396,7 +402,9 @@ class PreserveLoggingContext(object): __slots__ = ["current_context", "new_context", "has_parent"] - def __init__(self, new_context=LoggingContext.sentinel): + def __init__(self, new_context=None): + if new_context is None: + new_context = LoggingContext.sentinel self.new_context = new_context def __enter__(self):