Skip to content

fix(server): replace readSliceShort with posix.read to fix HTTP hang#7

Open
YeonV wants to merge 1 commit intonullclaw:mainfrom
YeonV:fix/http-server-read-hang
Open

fix(server): replace readSliceShort with posix.read to fix HTTP hang#7
YeonV wants to merge 1 commit intonullclaw:mainfrom
YeonV:fix/http-server-read-hang

Conversation

@YeonV
Copy link
Copy Markdown

@YeonV YeonV commented May 7, 2026

Problem

After the Zig 0.16 migration (#5 / 54fe635), readHttpRequest reads incoming data using reader.interface.readSliceShort():

var reader = stream.reader(std_compat.io(), &read_buffer);
const n = try reader.interface.readSliceShort(&chunk);

readSliceShort loops until the entire chunk buffer (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 readSliceShort with std.posix.read, which is a single-syscall partial read that returns immediately with however many bytes are available:

const n = std.posix.read(stream.socket.handle, &chunk) catch return error.ReadFailed;

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.

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.
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.

1 participant