mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Merge pull request #3144 from matrix-org/rav/run_in_background_exception_handling
Trap exceptions thrown within run_in_background
This commit is contained in:
commit
fdb6849b81
@ -313,7 +313,13 @@ def run_in_background(f, *args, **kwargs):
|
|||||||
indication about where it came from.
|
indication about where it came from.
|
||||||
"""
|
"""
|
||||||
current = LoggingContext.current_context()
|
current = LoggingContext.current_context()
|
||||||
|
try:
|
||||||
res = f(*args, **kwargs)
|
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.
|
||||||
|
Loading…
Reference in New Issue
Block a user