diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-12 17:23:34 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:16 -0300 |
| commit | 9dd6f001c7d5eee987cbd305a79d1b1d011b83f5 (patch) | |
| tree | 2ec5b20565b162b54cdfef9ae5d8fec0e57dfb54 /src | |
| parent | 7a07e24916cd5bc762996d81aa1faf550177cd6f (diff) | |
| download | cloud9-9dd6f001c7d5eee987cbd305a79d1b1d011b83f5.tar.gz cloud9-9dd6f001c7d5eee987cbd305a79d1b1d011b83f5.zip | |
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 'src')
| -rw-r--r-- | src/serve.zig | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/serve.zig b/src/serve.zig index ad774a3..7ee47ba 100644 --- a/src/serve.zig +++ b/src/serve.zig @@ -123,6 +123,7 @@ pub fn Runner(comptime Backend: type, comptime opts: fs.Options, comptime limits flags: std.atomic.Value(u8) = .init(0), signal: Io.Event = .unset, room: Io.Event = .unset, + output_room: Io.Condition = .init, used: std.atomic.Value(bool) = .init(false), in: [msize]u8 = undefined, out: [2 * msize]u8 = undefined, @@ -152,6 +153,32 @@ pub fn Runner(comptime Backend: type, comptime opts: fs.Options, comptime limits c.raise(output); } + /// Completion from an independent task. Keep one full frame of + /// output capacity reserved for the synchronous handler that the + /// connection loop may already have dispatched. Waiting must not + /// hold a backend lock: that handler must be able to finish so the + /// connection loop can drain output. Cancellation/clunk must join + /// the producer task before this connection slot can be reused. + pub fn replyAsync(c: *Conn, r: *const Backend.Reply, bytes: []const u8) Io.Cancelable!void { + const io = c.runner.io; + c.lock(); + defer c.unlock(); + while (true) { + if (c.engine.protocol.dead or c.runner.stopping.load(.acquire)) { + return; + } + _ = c.engine.protocol.hasRoom(); // compact drained prefix + const reserve = 2 * @as(usize, @max(c.engine.protocol.msize, 24)); + if (c.engine.protocol.out.len - c.engine.protocol.out_len >= reserve) { + c.engine.reply(r, bytes); + c.raise(output); + return; + } + c.raise(output); + try c.output_room.wait(io, &c.mutex); + } + } + /// Answers a read or write `.again` and hands back the ticket /// of the park, to answer it through `answerWith()` when the backend /// has something (lib9p's kept Req); null when it could not @@ -230,6 +257,7 @@ pub fn Runner(comptime Backend: type, comptime opts: fs.Options, comptime limits c.flags = .init(0); c.signal = .unset; c.room = .unset; + c.output_room = .init; // Under the lock: the slot is already visible as live. c.lock(); c.engine.initIn(.{ .in = &c.in, .out = &c.out, .root = r.root, .seed = r.seed ^ c.index }); @@ -315,6 +343,7 @@ pub fn Runner(comptime Backend: type, comptime opts: fs.Options, comptime limits return; }; c.engine.wrote(pending.len); + c.output_room.broadcast(io); const dead = c.engine.protocol.dead; greeted = greeted or c.engine.protocol.msize != 0; c.unlock(); |
