summaryrefslogtreecommitdiff
path: root/web/catalog.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-12 17:23:34 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:16 -0300
commit9dd6f001c7d5eee987cbd305a79d1b1d011b83f5 (patch)
tree2ec5b20565b162b54cdfef9ae5d8fec0e57dfb54 /web/catalog.zig
parent7a07e24916cd5bc762996d81aa1faf550177cd6f (diff)
downloadcloud9-9dd6f001c7d5eee987cbd305a79d1b1d011b83f5.tar.gz
cloud9-9dd6f001c7d5eee987cbd305a79d1b1d011b83f5.zip
9web: backpressure asynchronous replies under parallel site loadHEADmain
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.
Diffstat (limited to 'web/catalog.zig')
-rw-r--r--web/catalog.zig15
1 files changed, 7 insertions, 8 deletions
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) {