diff options
author | Richard van der Hoff <github@rvanderhoff.org.uk> | 2017-11-07 10:47:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-07 10:47:00 +0000 |
commit | ec12e7eada708e28e4291448a1ced2703f232f2b (patch) | |
tree | 577c099f45a4b944f5038685418fc3f39f10fe9b /synapse/util/async.py | |
parent | Merge pull request #2630 from matrix-org/luke/fix-rooms-in-group (diff) | |
parent | Logging and logcontext fixes for Limiter (diff) | |
download | synapse-ec12e7eada708e28e4291448a1ced2703f232f2b.tar.xz |
Merge pull request #2646 from matrix-org/rav/logging_for_limiter
Logging and logcontext fixes for Limiter
Diffstat (limited to 'synapse/util/async.py')
-rw-r--r-- | synapse/util/async.py | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/synapse/util/async.py b/synapse/util/async.py index 1a884e96ee..e786fb38a9 100644 --- a/synapse/util/async.py +++ b/synapse/util/async.py @@ -278,8 +278,13 @@ class Limiter(object): if entry[0] >= self.max_count: new_defer = defer.Deferred() entry[1].append(new_defer) + + logger.info("Waiting to acquire limiter lock for key %r", key) with PreserveLoggingContext(): yield new_defer + logger.info("Acquired limiter lock for key %r", key) + else: + logger.info("Acquired uncontended limiter lock for key %r", key) entry[0] += 1 @@ -288,16 +293,21 @@ class Limiter(object): try: yield finally: + logger.info("Releasing limiter lock for key %r", key) + # We've finished executing so check if there are any things # blocked waiting to execute and start one of them entry[0] -= 1 - try: - entry[1].pop(0).callback(None) - except IndexError: - # If nothing else is executing for this key then remove it - # from the map - if entry[0] == 0: - self.key_to_defer.pop(key, None) + + if entry[1]: + next_def = entry[1].pop(0) + + with PreserveLoggingContext(): + next_def.callback(None) + elif entry[0] == 0: + # We were the last thing for this key: remove it from the + # map. + del self.key_to_defer[key] defer.returnValue(_ctx_manager()) |