Commit a92e4dd
committed
fix: cap proxy buffer to stop long-stream heap leak + Invalid string length crash
aimock's proxy/record path buffered an entire upstream streaming response in
memory with no size cap, accumulating per-frame state (frameTimestamps, frame
buffers, chunks) for a stream's full lifetime. Long-lived nested-sub-agent
proxied streams drove a slow heap climb to OOM (~8.4GB/25h) and a single
oversized response threw RangeError: Invalid string length.
Enforce byte AND frame-count caps on the proxy buffer, checked per-frame inside
the SSE/NDJSON and binary EventStream loops (not just at chunk boundaries) and
on the binary parse buffer; clear all accumulators when a cap trips; clean up
on client disconnect. The client relay is preserved: non-streamed over-cap
bodies are relayed in full (status normalized) up to a 256MiB hard ceiling,
above which the proxy fails loud with a 502 rather than relaying a silently
truncated body. Adds --max-proxy-buffer-bytes / --max-proxy-buffer-frames.1 parent ef7cd92 commit a92e4dd
5 files changed
Lines changed: 1308 additions & 24 deletions
0 commit comments