Skip to content

Do not log a traceback when a TLS client disconnects mid-response - #1261

Open
Yohan-Senadheera wants to merge 1 commit into
prometheus:masterfrom
Yohan-Senadheera:ignore-tls-eof
Open

Yohan-Senadheera wants to merge 1 commit into
prometheus:masterfrom
Yohan-Senadheera:ignore-tls-eof

Conversation

@Yohan-Senadheera

Copy link
Copy Markdown

Fixes #983.

When a client drops the connection while /metrics is being written, wsgiref ignores BrokenPipeError and ConnectionResetError. Over TLS the same disconnect raises ssl.SSLEOFError, which wsgiref does not ignore, so handle_error() prints a full traceback. The server keeps working, but the traceback looks like a crash (as in #983).

This adds a ServerHandler subclass whose handle_error() ignores SSLEOFError the same way, and _SilentHandler.handle() uses it. handle() is the same as WSGIRequestHandler.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:

  • master: 3 tracebacks ending in ssl.SSLEOFError: EOF occurred in violation of protocol
  • this branch: nothing on stderr; the next scrape still returns 200

The new tests check that SSLEOFError is not logged and that other errors still are. The full test suite, flake8 and isort pass.

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 <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 18, 2026 02:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exceptions not handled in server thread

2 participants