Swallow client-hangup errors in the serve HTTP handler#25
Merged
Conversation
Podman's shell driver uses curl -sf, which exits as soon as it sees a non-2xx status and closes the socket before the server has finished writing the response body. The handler's self.wfile.write(body) then raises BrokenPipeError, which escapes into stdlib BaseHTTPRequestHandler and is logged as a full traceback. Every failed auth lookup (wrong token, missing token, 401) generated a fresh stack trace in the journal. Extract a single _write_response() helper that both _respond and _respond_error call. Wrap end_headers() and wfile.write() in a try/except that swallows BrokenPipeError and ConnectionResetError — normal peer-hangup conditions for any HTTP server. Tests cover a 401 path with a BrokenPipeError-raising wfile and a 200 path with ConnectionResetError, asserting do_GET() does not propagate.
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.
Summary
_write_response()helper inpsi/serve.pythat both_respondand_respond_errorcall. It wrapsend_headers()andwfile.write(body)in a try/except that swallowsBrokenPipeErrorandConnectionResetError.BaseHTTPRequestHandlerand got logged as full tracebacks, polluting journals on every failed auth lookup (curl -sf closes the socket as soon as it sees a non-2xx).Test plan
pytest tests/test_serve.py— newTestClientHangupclass: 401 path with aBrokenPipeError-raisingwfileand 200 path withConnectionResetError, assertingdo_GET()does not propagate.ruff check/ruff format --check/ty check— clean.