Merge pull request #3927 from matrix-org/erikj/handle_background_errors

Handle exceptions thrown by background tasks
This commit is contained in:
Erik Johnston 2018-09-21 09:26:30 +01:00 committed by GitHub
commit ad53a5497d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

1
changelog.d/3927.misc Normal file
View file

@ -0,0 +1 @@
Log exceptions thrown by background tasks

View file

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import threading
import six
@ -23,6 +24,9 @@ from twisted.internet import defer
from synapse.util.logcontext import LoggingContext, PreserveLoggingContext
logger = logging.getLogger(__name__)
_background_process_start_count = Counter(
"synapse_background_process_start_count",
"Number of background processes started",
@ -191,6 +195,8 @@ def run_as_background_process(desc, func, *args, **kwargs):
try:
yield func(*args, **kwargs)
except Exception:
logger.exception("Background process '%s' threw an exception", desc)
finally:
proc.update_metrics()