From 9dd6f001c7d5eee987cbd305a79d1b1d011b83f5 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 12 Oct 2026 17:23:34 -0300 Subject: 9web: backpressure asynchronous replies under parallel site load Reserve output space for an async completion plus the already-dispatched synchronous handler. Wait on a condition without the catalogue mutex, preserving cancellation and connection-slot lifetime. Abort HTTP streaming on an upstream error instead of hiding a truncated response. Reproduced the former failure with concurrent live cafe assets. Add exact-hash load checks with 16 readers, mixed HEAD and 40 interrupted downloads; validate 80 multi-frame responses over 37 live files. All five live sites, mounted 9P browsing, protocol/catalogue/host/HTTP/mux/UI tests and 32 original E2E scenarios pass. Deploy corrected service on sole [::]:8090. See docs/namespace-sites-validation.md. --- web/catalog.zig | 15 +++++++-------- web/httpfs.zig | 4 +++- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'web') diff --git a/web/catalog.zig b/web/catalog.zig index d375973..977e0ae 100644 --- a/web/catalog.zig +++ b/web/catalog.zig @@ -540,13 +540,15 @@ pub const Catalog = struct { } fn readTask(cat: *Catalog, conn: *Runner.Conn, req: fs.Req, file: Io.File, slot: usize) void { defer file.close(cat.io); + defer { + cat.mutex.lockUncancelable(cat.io); + cat.reads[conn.index][slot] = 0; + cat.mutex.unlock(cat.io); + } var arena = std.heap.ArenaAllocator.init(A); defer arena.deinit(); const b = arena.allocator().alloc(u8, req.size) catch { - cat.mutex.lockUncancelable(cat.io); - defer cat.mutex.unlock(cat.io); - replyError(conn, req.tag, error.OutOfMemory); - cat.reads[conn.index][slot] = 0; + conn.replyAsync(&.{ .tag = req.tag, .status = .err, .ename = "OutOfMemory" }, "") catch {}; return; }; const result = file.readPositional(cat.io, &.{b}, req.off) catch |err| switch (err) { @@ -556,10 +558,7 @@ pub const Catalog = struct { }, else => err, }; - cat.mutex.lockUncancelable(cat.io); - defer cat.mutex.unlock(cat.io); - if (result) |n| conn.reply(&.{ .tag = req.tag }, b[0..n]) else |err| replyError(conn, req.tag, err); - cat.reads[conn.index][slot] = 0; + if (result) |n| conn.replyAsync(&.{ .tag = req.tag }, b[0..n]) catch {} else |err| conn.replyAsync(&.{ .tag = req.tag, .status = .err, .ename = @errorName(err) }, "") catch {}; } fn replyError(conn: *Runner.Conn, tag: u64, err: anyerror) void { const message = switch (err) { diff --git a/web/httpfs.zig b/web/httpfs.zig index 31c4014..479dd09 100644 --- a/web/httpfs.zig +++ b/web/httpfs.zig @@ -313,7 +313,9 @@ fn FS(comptime M: type) type { if (sent >= limit or data.len == 0) break; offset += data.len; const r = try self.readAt(leaf, offset, self.chunk()); - if (r.msg != .rread) break; + // Do not terminate chunked HTTP successfully after a 9P + // error: the client must detect the incomplete response. + if (r.msg != .rread) return error.Upstream; data = r.msg.rread.data; if (data.len == 0) break; } -- cgit v1.3