mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-29 07:28:55 +03:00
Fix logcontext leaks in rate limiter
This commit is contained in:
parent
d72faf2fad
commit
a7fe62f0cb
1 changed files with 14 additions and 3 deletions
|
@ -18,7 +18,10 @@ from twisted.internet import defer
|
||||||
from synapse.api.errors import LimitExceededError
|
from synapse.api.errors import LimitExceededError
|
||||||
|
|
||||||
from synapse.util.async import sleep
|
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 collections
|
||||||
import contextlib
|
import contextlib
|
||||||
|
@ -176,6 +179,9 @@ class _PerHostRatelimiter(object):
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def on_err(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)
|
self.current_processing.discard(request_id)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
@ -187,7 +193,7 @@ class _PerHostRatelimiter(object):
|
||||||
|
|
||||||
ret_defer.addCallbacks(on_start, on_err)
|
ret_defer.addCallbacks(on_start, on_err)
|
||||||
ret_defer.addBoth(on_both)
|
ret_defer.addBoth(on_both)
|
||||||
return ret_defer
|
return make_deferred_yieldable(ret_defer)
|
||||||
|
|
||||||
def _on_exit(self, request_id):
|
def _on_exit(self, request_id):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
@ -197,7 +203,12 @@ class _PerHostRatelimiter(object):
|
||||||
self.current_processing.discard(request_id)
|
self.current_processing.discard(request_id)
|
||||||
try:
|
try:
|
||||||
request_id, deferred = self.ready_request_queue.popitem()
|
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)
|
self.current_processing.add(request_id)
|
||||||
deferred.callback(None)
|
|
||||||
|
with PreserveLoggingContext():
|
||||||
|
deferred.callback(None)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
Loading…
Reference in a new issue