diff options
Diffstat (limited to 'web')
| -rw-r--r-- | web/catalog.zig | 15 | ||||
| -rw-r--r-- | web/httpfs.zig | 4 |
2 files changed, 10 insertions, 9 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) { 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; } |
