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

_run_push_actions_and_persist_event re-starts a finished logging context when persist_events_and_notify raises an exception #12987

Closed
squahtx opened this issue Jun 8, 2022 · 2 comments · Fixed by #13089
Labels
A-Federation S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@squahtx
Copy link
Contributor

squahtx commented Jun 8, 2022

When persist_events_and_notify raises an exception, we try to clean up push actions in a background task:

try:
await self.persist_events_and_notify(
event.room_id, [(event, context)], backfilled=backfilled
)
except Exception:
run_in_background(
self._store.remove_push_actions_from_staging, event.event_id
)
raise

run_in_background inherits the current logging context, but since we don't await the background task, we end up closing the logging context before the background task finishes. We ought to either await remove_push_actions_from_staging directly, or create a logging context for it.

@squahtx squahtx added A-Federation S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels Jun 8, 2022
@squahtx
Copy link
Contributor Author

squahtx commented Jun 8, 2022

Actually every call to run_in_background where we discard the return value probably has the same issue.

@squahtx squahtx changed the title _run_push_actions_and_persist_event reuses a finished logging context when persist_events_and_notify raises an exception _run_push_actions_and_persist_event re-starts a finished logging context when persist_events_and_notify raises an exception Jun 8, 2022
@clokep
Copy link
Member

clokep commented Jun 8, 2022

Actually every call to run_in_background where we discard the return value probably has the same issue.

I think grep -r " run_in_background" synapse (note the two spaces before it) would be a quick way to find those. I see a bunch. 😢

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Federation S-Tolerable Minor significance, cosmetic issues, low or no impact to users. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants