mirror of
https://mau.dev/maunium/synapse.git
synced 2024-08-22 02:05:24 +00:00
Merge pull request #3927 from matrix-org/erikj/handle_background_errors
Handle exceptions thrown by background tasks
This commit is contained in:
commit
ad53a5497d
1
changelog.d/3927.misc
Normal file
1
changelog.d/3927.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Log exceptions thrown by background tasks
|
@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import logging
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
import six
|
import six
|
||||||
@ -23,6 +24,9 @@ from twisted.internet import defer
|
|||||||
|
|
||||||
from synapse.util.logcontext import LoggingContext, PreserveLoggingContext
|
from synapse.util.logcontext import LoggingContext, PreserveLoggingContext
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
_background_process_start_count = Counter(
|
_background_process_start_count = Counter(
|
||||||
"synapse_background_process_start_count",
|
"synapse_background_process_start_count",
|
||||||
"Number of background processes started",
|
"Number of background processes started",
|
||||||
@ -191,6 +195,8 @@ def run_as_background_process(desc, func, *args, **kwargs):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
yield func(*args, **kwargs)
|
yield func(*args, **kwargs)
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Background process '%s' threw an exception", desc)
|
||||||
finally:
|
finally:
|
||||||
proc.update_metrics()
|
proc.update_metrics()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user