Skip to content

Return an error at EOF while reading the PROXY protocol header - #582

Open
armaxri wants to merge 1 commit into
bolcom:masterfrom
armaxri:fix/proxy-header-eof-spin
Open

armaxri wants to merge 1 commit into
bolcom:masterfrom
armaxri:fix/proxy-header-eof-spin

Conversation

@armaxri

@armaxri armaxri commented Oct 6, 2026

Copy link
Copy Markdown

Fixes #580.

read_proxy_header loops forever when the peer closes the connection before the header's
newline arrives: peek returns Ok(0) at EOF, no newline is found, and the zero-length
read in the None branch returns Ok(0) too.

peek only returns Ok(0) at EOF (the buffer is never empty), so this checks for it right
after the peek and returns ProxyError::ReadError with io::ErrorKind::UnexpectedEof. The
spawned header task then logs "proxy protocol read error" and ends, like for every other
header error. Behaviour for connections that do send a header is unchanged.

Two tests cover EOF before any byte and EOF after a partial header; both used to hang and now
return the error (they are bounded by a 5 s timeout so a regression fails instead of hanging).

read_proxy_header looped forever when the peer closed the connection
before the header's newline arrived: peek returns Ok(0) at EOF, no
newline is found, and the zero-length read in the None branch returns
Ok(0) too. Treat Ok(0) from peek as UnexpectedEof so the header task
logs the error and ends.

Fixes bolcom#580

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

PROXY protocol mode: header reader task spins forever when a connection closes before the header

1 participant