summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-01-16 11:47:36 +0000
committerRichard van der Hoff <richard@matrix.org>2018-01-16 11:47:36 +0000
commit64ddec1bc0a1d23a285d560e34986441b3f8c854 (patch)
treec4afa270e8c667dc295c41d781625be541daeb7b
parentMerge pull request #2778 from matrix-org/rav/counters_should_be_floats (diff)
downloadsynapse-64ddec1bc0a1d23a285d560e34986441b3f8c854.tar.xz
Fix a logcontext leak in persist_events
ObserveableDeferred expects its callbacks to be called without any
logcontexts, whereas it turns out we were calling them with the logcontext of
the request which initiated the persistence loop.

It seems wrong that we are attributing work done in the persistence loop to the
request that happened to initiate it, so let's solve this by dropping the
logcontext for it.

(I'm not sure this actually causes any real problems other than messages in the
debug log, but let's clean it up anyway)
-rw-r--r--synapse/storage/events.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index d08f7571d7..ad1d782705 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -146,6 +146,9 @@ class _EventPeristenceQueue(object):
             try:
                 queue = self._get_drainining_queue(room_id)
                 for item in queue:
+                    # handle_queue_loop runs in the sentinel logcontext, so
+                    # there is no need to preserve_fn when running the
+                    # callbacks on the deferred.
                     try:
                         ret = yield per_item_callback(item)
                         item.deferred.callback(ret)
@@ -157,7 +160,11 @@ class _EventPeristenceQueue(object):
                     self._event_persist_queues[room_id] = queue
                 self._currently_persisting_rooms.discard(room_id)
 
-        preserve_fn(handle_queue_loop)()
+        # set handle_queue_loop off on the background. We don't want to
+        # attribute work done in it to the current request, so we drop the
+        # logcontext altogether.
+        with PreserveLoggingContext():
+            handle_queue_loop()
 
     def _get_drainining_queue(self, room_id):
         queue = self._event_persist_queues.setdefault(room_id, deque())