Remove logcontext problems caused by awaiting raw deferLater(...)#19058
Merged
MadLittleMods merged 9 commits intodevelopfrom Oct 29, 2025
Merged
Conversation
``` builtins.AssertionError: Expected `looping_call` callback from the reactor to start with the sentinel logcontext but saw task-_resumable_task-0-IBzAmHUoepQfLnEA. In other words, another task shouldn't have leaked their logcontext to us. ```
MadLittleMods
commented
Oct 13, 2025
Comment on lines
+174
to
+177
| # Create a deferred which we will never complete | ||
| incomplete_d: Deferred = Deferred() | ||
| # Await forever to simulate an aborted task because of a restart | ||
| await deferLater(self.reactor, 2**16, lambda: None) | ||
| await make_deferred_yieldable(incomplete_d) |
Contributor
Author
There was a problem hiding this comment.
Since the goal is to wait forever, let's actually wait forever instead of 2**16 seconds.
MadLittleMods
commented
Oct 13, 2025
| self, task: ScheduledTask | ||
| ) -> Tuple[TaskStatus, Optional[JsonMapping], Optional[str]]: | ||
| # Sleep for a second | ||
| await deferLater(self.reactor, 1, lambda: None) |
Contributor
Author
There was a problem hiding this comment.
We could have also fixed this by wrapping the deferred with make_deferred_yieldable(...). (see our logcontext docs
ex. await make_deferred_yieldable(deferLater(self.reactor, 1, lambda: None))
Instead, I've opted to replace all of our deferLater usage with more proper clock utilities that handle logcontext rules already.
deferLaterdeferLater(...)
3 tasks
anoadragon453
approved these changes
Oct 29, 2025
Contributor
Author
|
Thanks for the review @anoadragon453 🐆 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Remove logcontext problems caused by raw
deferLater. This is a normal problem where weawaita deferred without wrapping it inmake_deferred_yieldable(...). But I've opted to replace the usage ofdeferLaterwith something more standard for the Synapse codebase.Part of #18905
It's unclear why we're only now seeing these failures happen with the changes from #19057
Example failures seen in https://github.com/element-hq/synapse/actions/runs/18477454390/job/52645183606?pr=19057
Dev notes
Our logcontext docs:
docs/log_contexts.mdPull Request Checklist
EventStoretoEventWorkerStore.".code blocks.