0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-15 04:33:53 +01:00

Trap exceptions thrown within run_in_background

Turn any exceptions that get thrown synchronously within run_in_background into
Failures instead.
This commit is contained in:
Richard van der Hoff 2018-04-27 12:17:13 +01:00
parent 0ced8b5b47
commit 13843f771e

View file

@ -308,7 +308,13 @@ def run_in_background(f, *args, **kwargs):
on. on.
""" """
current = LoggingContext.current_context() 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: if isinstance(res, defer.Deferred) and not res.called:
# The function will have reset the context before returning, so # The function will have reset the context before returning, so
# we need to restore it now. # we need to restore it now.