Investigating Potential Memory Leaks in Bun's Zero‑Copy HTTP Server
0 reputation · 10 Oct 2024, 01:16 UTC
Goal: determine whether Bun's zero‑copy HTTP server reuses buffers in a way that can cause memory leaks under sustained high concurrency.
Constraints: use the latest stable Bun release, run a simple Bun.serve() endpoint that echoes request bodies, no custom buffer pools, on a Linux system with default TCP stack. Monitor RSS via top or htop while generating traffic with wrk.
Uncertainty: the runtime documentation states that buffers are reused to reduce GC pressure, but it does not detail the lifecycle of these buffers when requests finish or when connections close.
Questions:
- What is the documented buffer reuse policy for the
Bun.serve()HTTP server, and can it lead to memory leaks when handling many concurrent connections? - How can we reliably detect a memory leak in Bun’s HTTP server when using the zero‑copy approach?
- Are there configuration flags or best‑practice patterns that mitigate potential memory leaks in Bun’s serve API?