fix(server): replace readSliceShort with posix.read to fix HTTP hang#7
Open
YeonV wants to merge 1 commit intonullclaw:mainnullclaw/nullboiler:mainfrom
YeonV:fix/http-server-read-hangYeonV/nullboiler:fix/http-server-read-hangCopy head branch name to clipboard
Open
fix(server): replace readSliceShort with posix.read to fix HTTP hang#7YeonV wants to merge 1 commit intonullclaw:mainnullclaw/nullboiler:mainfrom YeonV:fix/http-server-read-hangYeonV/nullboiler:fix/http-server-read-hangCopy head branch name to clipboard
YeonV wants to merge 1 commit intonullclaw:mainnullclaw/nullboiler:mainfrom
YeonV:fix/http-server-read-hangYeonV/nullboiler:fix/http-server-read-hangCopy head branch name to clipboard
Conversation
After the Zig 0.16 migration (54fe635), readHttpRequest used reader.interface.readSliceShort() to read incoming data. However, readSliceShort loops until the entire 4096-byte buffer is filled before returning. Since typical HTTP requests are much smaller than 4096 bytes, the server would block indefinitely waiting for data that never arrives. Fix: replace readSliceShort with std.posix.read, which returns immediately with however many bytes are available — the correct behaviour for an HTTP request reader.
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
After the Zig 0.16 migration (#5 /
54fe635),readHttpRequestreads incoming data usingreader.interface.readSliceShort():readSliceShortloops until the entirechunkbuffer (4096 bytes) is completely filled before returning. Since a typical HTTP request is far smaller than 4096 bytes, the socket read blocks indefinitely — the client sends its request, nullboiler never responds, and the connection times out.Fix
Replace
readSliceShortwithstd.posix.read, which is a single-syscall partial read that returns immediately with however many bytes are available:This is the correct semantics for an incremental HTTP request reader, and is consistent with how the pre-0.16 code used
stream.read(&chunk)directly.Impact
Without this fix, every HTTP request to nullboiler hangs — the server accepts the TCP connection but never sends a response. The process appears healthy but is completely non-functional.