Fix std.http.Server unreachable panic (one request per connection)#12
Open
ch4r10t33r wants to merge 3 commits intomainfrom
Open
Fix std.http.Server unreachable panic (one request per connection)#12ch4r10t33r wants to merge 3 commits intomainfrom
ch4r10t33r wants to merge 3 commits intomainfrom
Conversation
- Handle one request per TCP connection to avoid Zig std.http.Server discardBody() unreachable when reusing the same connection - Add keep_alive = false and transfer_encoding = .none on all responses so we never enter the stdlib state machine path that hits unreachable - Validated locally and on remote host (no panic under load)
Use methodName() switch instead of @TagName(method) to avoid 'invalid enum value' panic when clients send unexpected HTTP methods (e.g. health checks, probes). Unknown methods log as OTHER.
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.
Problem
Leanpoint crashed with
thread 1 panic: reached unreachable codeinservewhen handling HTTP requests. The panic occurs in Zig'sstd.http.ServerdiscardBody()when reusing the same connection (state machine hitselse => unreachable).Solution
One request per connection – Accept a connection, handle exactly one
receiveHead()+handleRequest(), then continue to the nextaccept(). We never callreceiveHead()again on the sameServerinstance, so we avoid the stdlib state machine path that triggers the unreachable.keep_alive = false– All responses sendConnection: closeso we never try to reuse the connection on the server side.transfer_encoding = .none– All responses use Content-Length only (no chunked encoding) for a simpler response path.Validation
/,/status,/healthz– no panic, server stayed up.upstreams-ansible.json, 40 requests – no panic, container stayed up.