From 87ed2d73cbbf788167bd9a2777b2461abcf78ecb Mon Sep 17 00:00:00 2001 From: Yeon Vinzenz Varapragasam Date: Thu, 7 May 2026 16:11:52 +0200 Subject: [PATCH] fix(server): replace readSliceShort with posix.read to fix HTTP hang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/main.zig | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.zig b/src/main.zig index 8ea8451..f21c247 100644 --- a/src/main.zig +++ b/src/main.zig @@ -464,12 +464,10 @@ fn readHttpRequest(allocator: std.mem.Allocator, stream: *std.Io.net.Stream, max var header_end: ?usize = null; var content_len: usize = 0; - var read_buffer: [request_read_chunk]u8 = undefined; - var reader = stream.reader(std_compat.io(), &read_buffer); var chunk: [request_read_chunk]u8 = undefined; while (true) { - const n = try reader.interface.readSliceShort(&chunk); + const n = std.posix.read(stream.socket.handle, &chunk) catch return error.ReadFailed; if (n == 0) return null; try buffer.appendSlice(allocator, chunk[0..n]);