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

Trap exceptions thrown within run_in_background #3144

Merged
merged 1 commit into from
Apr 30, 2018
Merged
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
8 changes: 7 additions & 1 deletion synapse/util/logcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,13 @@ def run_in_background(f, *args, **kwargs):
on.
"""
current = LoggingContext.current_context()
res = f(*args, **kwargs)
try:
res = f(*args, **kwargs)
except: # noqa: E722
# the assumption here is that the caller doesn't want to be disturbed
# by synchronous exceptions, so let's turn them into Failures.
return defer.fail()

if isinstance(res, defer.Deferred) and not res.called:
# The function will have reset the context before returning, so
# we need to restore it now.
Expand Down