summaryrefslogtreecommitdiff
path: root/synapse/metrics/background_process_metrics.py
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2018-12-18 16:54:37 +0100
committerAndrej Shadura <andrewsh@debian.org>2018-12-18 16:54:37 +0100
commit009f8e9becfd911e5ebfc5f76f91c32f30e841fb (patch)
tree57cba64a92a4f44dbb793bcac82c183914b579bc /synapse/metrics/background_process_metrics.py
parent8e06f4e756a71e9ed81e46b1cc091f0ea78bbcb6 (diff)
parentd74515335df48009cfa750ea7955c7195171978b (diff)
Merge tag 'debian/0.33.9-2' into debian/stretch-backportsdebian/0.33.9-2_bpo9+1
matrix-synapse release 0.33.9-2 for unstable (sid) (maintainer view tag generated by dgit --quilt=gbp)
Diffstat (limited to 'synapse/metrics/background_process_metrics.py')
-rw-r--r--synapse/metrics/background_process_metrics.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/synapse/metrics/background_process_metrics.py b/synapse/metrics/background_process_metrics.py
index 167167be..037f1c49 100644
--- a/synapse/metrics/background_process_metrics.py
+++ b/synapse/metrics/background_process_metrics.py
@@ -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",
@@ -97,9 +101,13 @@ class _Collector(object):
labels=["name"],
)
- # We copy the dict so that it doesn't change from underneath us
+ # We copy the dict so that it doesn't change from underneath us.
+ # We also copy the process lists as that can also change
with _bg_metrics_lock:
- _background_processes_copy = dict(_background_processes)
+ _background_processes_copy = {
+ k: list(v)
+ for k, v in six.iteritems(_background_processes)
+ }
for desc, processes in six.iteritems(_background_processes_copy):
background_process_in_flight_count.add_metric(
@@ -191,6 +199,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()