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

Commit 49a683d

Browse files
authored
Fix long-standing bug where ReadWriteLock could drop logging contexts (#10993)
Use `PreserveLoggingContext()` to ensure that logging contexts are not lost when exiting a read/write lock. When exiting a read/write lock, callbacks on a `Deferred` are triggered as a signal to any waiting coroutines. Any waiting coroutine that becomes runnable is likely to follow the Synapse logging context rules and will restore its own logging context, then either run to completion or await another `Deferred`, resetting the logging context in the process.
1 parent bb228f3 commit 49a683d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

changelog.d/10993.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a long-standing bug where `ReadWriteLock`s could drop logging contexts on exit.

synapse/util/async_helpers.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ def _ctx_manager():
438438
try:
439439
yield
440440
finally:
441-
new_defer.callback(None)
441+
with PreserveLoggingContext():
442+
new_defer.callback(None)
442443
self.key_to_current_readers.get(key, set()).discard(new_defer)
443444

444445
return _ctx_manager()
@@ -466,7 +467,8 @@ def _ctx_manager():
466467
try:
467468
yield
468469
finally:
469-
new_defer.callback(None)
470+
with PreserveLoggingContext():
471+
new_defer.callback(None)
470472
if self.key_to_current_writer[key] == new_defer:
471473
self.key_to_current_writer.pop(key)
472474

0 commit comments

Comments
 (0)