Skip to content

Commit

Permalink
Added handling of exceptions when starting the HTTP server
Browse files Browse the repository at this point in the history
Details:

* Added handling of IOError raised by start_http_server() in the HTTP case
  (it was already handled in the HTTPS case).

* For the HTTPS case, broadened the catching of IOError to now catch
  Exception, in order to make double sure that we catch everything, in order
  to investigate the issue with occasional ssl.SSLEOFError exceptions.

* Simplified and corrected the error message used for re-raising an exception
  raised by start_http_server() in the HTTPS case.

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Nov 15, 2023
1 parent 2d7e110 commit 2ee819f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ Released: not yet

* Test: Circumvented a pip-check-reqs issue by excluding its version 2.5.0.

* Added handling of exceptions raised by the built-in HTTP server during
its startup, for the HTTP case. (related to issue #397)

**Enhancements:**

* Added support for Python 3.12. Had to increase the minimum versions of
Expand Down
16 changes: 12 additions & 4 deletions zhmc_prometheus_exporter/zhmc_prometheus_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1868,12 +1868,20 @@ def main():
keyfile=server_key_file,
client_cafile=ca_cert_file,
client_auth_required=(ca_cert_file is not None))
except IOError as exc:
# pylint_ disable=broad-exception
except Exception as exc:
# We catch Exception for now in order to investigate the
# issue that with ssl.SSLEOFError being raised occasionally.
raise ImproperExit(
"Issues with server certificate, key, or CA certificate "
"files: {}: {}".format(exc.__class__.__name__, exc))
"Cannot start HTTPS server: {}: {}".
format(exc.__class__.__name__, exc))
else:
start_http_server(port=port)
try:
start_http_server(port=port)
except IOError as exc:
raise ImproperExit(
"Cannot start HTTP server: {}: {}".
format(exc.__class__.__name__, exc))

logprint(logging.INFO, PRINT_ALWAYS,
"Exporter is up and running on port {}".format(port))
Expand Down

0 comments on commit 2ee819f

Please sign in to comment.