Repository navigation
Do not log a traceback when a TLS client disconnects mid-response - #1261
Yohan-Senadheera wants to merge 1 commit into
Conversation
wsgiref ignores BrokenPipeError and ConnectionResetError when a client goes away during a response, but over TLS the same disconnect raises ssl.SSLEOFError, which is logged with a full traceback even though the server keeps working. Treat it like the other disconnect errors. Fixes prometheus#983 Signed-off-by: Yohan Senadheera <yohansenadheera@gmail.com>
chrikrah
left a comment
There was a problem hiding this comment.
Nothing blocks a merge: at 9d90462 TLS stays quiet where master prints an SSLEOFError traceback.
$ python inject.py tests/certs # start_wsgi_server with TLS, _SocketWriter.write raises SSLEOFError once
master c0f1bdf: stderr lines: 17 | SSLEOFError tracebacks: 1 | next scrape: 200
head 9d90462: stderr lines: 0 | SSLEOFError tracebacks: 0 | next scrape: 200
$ pytest -q tests # Python 3.12.14 and 3.14.7, head
493 passed, 16 skipped, 32 subtests passed
# guard removed from handle_error: test_dropped_tls_connection_is_not_logged fails
$ flake8 prometheus_client/ tests/ && isort --check prometheus_client/ tests/ # flake8 7.3, isort 5.10.1: exit 0
# not run: mypy env, pypy
non-blocking: the copied handle() matches stdlib on 3.9 to 3.15. Pin that with an inspect.getsource test, or skip it?
Thanks for testing it! I'd skip the getsource pin. It would fail on any harmless stdlib change in a patch release, and test_dropped_tls_connection_is_not_logged already fails if the guard is removed, so the behaviour is covered. Happy to add it if a maintainer prefers. |
|
Thanks @chrikrah for testing and approving this. @csmarchbanks, when you have a moment, could you take a look? CI is green and it's ready to merge. Happy to change anything if needed. |
Fixes #983.
When a client drops the connection while
/metricsis being written, wsgiref ignoresBrokenPipeErrorandConnectionResetError. Over TLS the same disconnect raisesssl.SSLEOFError, which wsgiref does not ignore, sohandle_error()prints a full traceback. The server keeps working, but the traceback looks like a crash (as in #983).This adds a
ServerHandlersubclass whosehandle_error()ignoresSSLEOFErrorthe same way, and_SilentHandler.handle()uses it.handle()is the same asWSGIRequestHandler.handle()apart from the handler class.Tested with
start_http_server(certfile=..., keyfile=...)and a TLS client that resets the connection after the first bytes, three times:ssl.SSLEOFError: EOF occurred in violation of protocolThe new tests check that
SSLEOFErroris not logged and that other errors still are. The full test suite, flake8 and isort pass.