diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2018-05-03 14:58:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-03 14:58:13 +0100 |
commit | 0ba609dc6fba3a2ca66b9b5e4b04a7504517e387 (patch) | |
tree | 2cc817cb92d986f347d3b07d8661b95abf632222 /synapse/util/ratelimitutils.py | |
parent | Merge pull request #3182 from Half-Shot/hs/fix-twisted-shutdown (diff) | |
parent | Fix logcontext leaks in rate limiter (diff) | |
download | synapse-0ba609dc6fba3a2ca66b9b5e4b04a7504517e387.tar.xz |
Merge pull request #3183 from matrix-org/rav/moar_logcontext_leaks
Fix logcontext leaks in rate limiter
Diffstat (limited to 'synapse/util/ratelimitutils.py')
-rw-r--r-- | synapse/util/ratelimitutils.py | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/synapse/util/ratelimitutils.py b/synapse/util/ratelimitutils.py index 18424f6c36..0ab63c3d7d 100644 --- a/synapse/util/ratelimitutils.py +++ b/synapse/util/ratelimitutils.py @@ -18,7 +18,10 @@ from twisted.internet import defer from synapse.api.errors import LimitExceededError from synapse.util.async import sleep -from synapse.util.logcontext import run_in_background +from synapse.util.logcontext import ( + run_in_background, make_deferred_yieldable, + PreserveLoggingContext, +) import collections import contextlib @@ -176,6 +179,9 @@ class _PerHostRatelimiter(object): return r def on_err(r): + # XXX: why is this necessary? this is called before we start + # processing the request so why would the request be in + # current_processing? self.current_processing.discard(request_id) return r @@ -187,7 +193,7 @@ class _PerHostRatelimiter(object): ret_defer.addCallbacks(on_start, on_err) ret_defer.addBoth(on_both) - return ret_defer + return make_deferred_yieldable(ret_defer) def _on_exit(self, request_id): logger.debug( @@ -197,7 +203,12 @@ class _PerHostRatelimiter(object): self.current_processing.discard(request_id) try: request_id, deferred = self.ready_request_queue.popitem() + + # XXX: why do we do the following? the on_start callback above will + # do it for us. self.current_processing.add(request_id) - deferred.callback(None) + + with PreserveLoggingContext(): + deferred.callback(None) except KeyError: pass |