Merge pull request #3309 from lightpanda-io/mcp-http-single-buffer

mcp: release a large HTTP response buffer after the reply
This commit is contained in:
Adrià Arrufat authored and GitHub committed 2026-08-27 21:45:21 +02:00
commit ce6f87f3c2
2 files changed
+7 -2

No files matched your search

+5
View File
@@ -35,6 +35,7 @@ const App = @import("../App.zig");
const sys_net = @import("../sys/net.zig");
const Server = @import("Server.zig");
const Transport = @import("Transport.zig");
const router = @import("router.zig");
const log = lp.log;
@@ -379,6 +380,10 @@ fn handleConn(self: *HttpServer, socket: posix.socket_t) void {
_ = arena.reset(.retain_capacity);
out.clearRetainingCapacity();
self.serve(&out.writer, arena.allocator(), &request) catch return;
if (out.writer.buffer.len > Transport.large_response) {
out.deinit();
out = .init(self.allocator);
}
if (!request.head.keep_alive or http_server.reader.state == .closing) return;
}
}
+2 -2
View File
@@ -25,7 +25,8 @@ const protocol = @import("protocol.zig");
const Self = @This();
const large_response = 256 * 1024;
/// A screenshot response is hundreds of KB; don't keep that parked.
pub const large_response = 256 * 1024;
writer: *std.Io.Writer,
mutex: std.Io.Mutex = .init,
@@ -56,7 +57,6 @@ pub fn sendResponse(self: *Self, response: anytype) !void {
try self.writer.writeAll(self.aw.writer.buffered());
try self.writer.flush();
// A screenshot response is hundreds of KB; don't keep that parked.
if (self.aw.writer.buffer.len > large_response) {
const allocator = self.aw.allocator;
self.aw.deinit();