Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix logcontext leaks in rate limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed May 3, 2018
1 parent d72faf2 commit a7fe62f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions synapse/util/ratelimitutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
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
Expand Down Expand Up @@ -176,6 +179,9 @@ def on_start(r):
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

Expand All @@ -187,7 +193,7 @@ def on_both(r):

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(
Expand All @@ -197,7 +203,12 @@ def _on_exit(self, request_id):
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

0 comments on commit a7fe62f

Please sign in to comment.