Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/19142.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Respect logcontext in `DeferredEvent`.
3 changes: 2 additions & 1 deletion synapse/util/async_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,8 @@ def __init__(self, clock: Clock) -> None:

def set(self) -> None:
if not self._deferred.called:
self._deferred.callback(None)
with PreserveLoggingContext():
self._deferred.callback(None)
Comment on lines +1032 to +1033
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix!

See the Deferred callbacks section of our logcontext docs for more info (specifically using solution 2).

Heads-up, I wrote the docs too so it's my assumptions/understanding all the way down. Apply your own scrutiny.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This usage is actually probably fine given you can't get a handle to the raw deferred and add some callbacks to the chain that could cause the logcontext to change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually a problem, see #19146 (comment) for an explanation


def clear(self) -> None:
if self._deferred.called:
Expand Down
Loading