From afdfc7748fd21ae517c4a0af088bd390e7fa9686 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 4 Feb 2020 12:59:32 -0600 Subject: [PATCH] mgr/telemetry: catch exception during requests.put Sometimes requests.put throws an exception. When that happens, generate an appropriate error but don't crash the module. Fixes: https://tracker.ceph.com/issues/43963 Signed-off-by: Sage Weil --- src/pybind/mgr/telemetry/module.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/pybind/mgr/telemetry/module.py b/src/pybind/mgr/telemetry/module.py index 97b35353893..ae3454e2948 100644 --- a/src/pybind/mgr/telemetry/module.py +++ b/src/pybind/mgr/telemetry/module.py @@ -673,16 +673,23 @@ class Module(MgrModule): for e in endpoint: if e == 'ceph': self.log.info('Sending ceph report to: %s', self.url) - resp = requests.put(url=self.url, json=report, proxies=proxies) - if not resp.ok: - self.log.error("Report send failed: %d %s %s" % - (resp.status_code, resp.reason, resp.text)) - failed.append('Failed to send report to %s: %d %s %s' % ( - self.url, - resp.status_code, - resp.reason, - resp.text - )) + fail_reason = None + try: + resp = requests.put(url=self.url, json=report, + proxies=proxies) + if not resp.ok: + fail_reason = 'Failed to send report to %s: %d %s %s' % ( + self.url, + resp.status_code, + resp.reason, + resp.text + ) + except Exception as e: + fail_reason = 'Failed to send report to %s: %s' % ( + self.url, str(e)) + if fail_reason: + self.log.error(fail_reason) + failed.append(fail_reason) else: now = int(time.time()) self.last_upload = now -- 2.47.3