Fix run_as_background_process not be awaited properly causing LoggingContext problems#18938
Merged
MadLittleMods merged 5 commits intodevelopfrom Sep 22, 2025
Conversation
Reproduction: ``` SYNAPSE_TEST_LOG_LEVEL=INFO poetry run trial tests.rest.client.test_delayed_events.DelayedEventsTestCase.test_cancel_delayed_state_event ``` Check `_trial_temp/test.log` (notice the `sentinel` log context) ``` 2025-09-18 10:58:23-0500 [-] synapse.handlers.delayed_events - 339 - INFO - POST-11 - asdf cancelling delayed event before _initialized_from_db syd_OlmchCwyUqznIXhlTDXQ ... 2025-09-18 10:58:23-0500 [-] synapse.handlers.delayed_events - 124 - INFO - _schedule_db_events-0 - asdf done _initialized_from_db 2025-09-18 10:58:23-0500 [-] synapse.handlers.delayed_events - 344 - INFO - sentinel - asdf cancelling delayed event after _initialized_from_db syd_OlmchCwyUqznIXhlTDXQ ```
MadLittleMods
commented
Sep 18, 2025
| (requester.user.to_string(), requester.device_id), | ||
| ) | ||
| await self._initialized_from_db | ||
| await make_deferred_yieldable(self._initialized_from_db) |
Contributor
Author
There was a problem hiding this comment.
As described in the docstring for why we need to do this:
synapse/synapse/metrics/background_process_metrics.py
Lines 231 to 234 in 4367fb2
(docstring updated in #18900)
If you're wondering what the problem looks like in practice, see 1668023
…round-process-sentinel-context
reivilibre
approved these changes
Sep 22, 2025
Contributor
Author
|
Thanks for the review @reivilibre 🦊 |
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.
Fix
run_as_background_processnot be awaited properly causingLoggingContextproblemsBasically, searching for any instance of
run_as_background_process(...)and making sure we wrap the deferred inmake_deferred_yieldable(...)if we try toawaitthe result to make it follow the Synapse logcontext rules.Part of #18905
Dev notes
The problem code was introduced in #17326
Pull Request Checklist
EventStoretoEventWorkerStore.".code blocks.