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

Commit

Permalink
Fix logging context misuse when we fail to persist a federation event (
Browse files Browse the repository at this point in the history
…#13089)

When we fail to persist a federation event, we kick off a task to remove
its push actions in the background, using the current logging context.
Since we don't `await` that task, we may finish our logging context
before the task finishes. There's no reason to not `await` the task, so
let's do that.

Signed-off-by: Sean Quah <seanq@matrix.org>
  • Loading branch information
squahtx authored Jun 17, 2022
1 parent 8ceed5e commit 9372f6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/13089.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug where a finished logging context would be re-started when Synapse failed to persist an event from federation.
6 changes: 2 additions & 4 deletions synapse/handlers/federation_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
from synapse.events import EventBase
from synapse.events.snapshot import EventContext
from synapse.federation.federation_client import InvalidResponseError
from synapse.logging.context import nested_logging_context, run_in_background
from synapse.logging.context import nested_logging_context
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.replication.http.devices import ReplicationUserDevicesResyncRestServlet
from synapse.replication.http.federation import (
Expand Down Expand Up @@ -1964,9 +1964,7 @@ async def _run_push_actions_and_persist_event(
event.room_id, [(event, context)], backfilled=backfilled
)
except Exception:
run_in_background(
self._store.remove_push_actions_from_staging, event.event_id
)
await self._store.remove_push_actions_from_staging(event.event_id)
raise

async def persist_events_and_notify(
Expand Down

0 comments on commit 9372f6f

Please sign in to comment.