Repository navigation
Do not log a traceback when a TLS client disconnects mid-response - #1261
Open
Yohan-Senadheera wants to merge 1 commit into
Open
Yohan-Senadheera wants to merge 1 commit into
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
approved these changes
Nov 24, 2026
chrikrah
left a comment
Contributor
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?
Author
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. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.