#1199·Vane

Memory leak: ~40 MB retained per interaction, never released (`next-server`)

Author: AirtheeCreated Sep 20, 2026Updated Sep 20, 2026
Labelsbug

Describe the bug

The Next.js server process (next-server) retains roughly 40 MB per user interaction and never gives it back. On my self-hosted instance the container reached 15.6 GB of anonymous memory (2.2 GB RSS + 13.4 GB swap) in 3.7 days and exhausted the host's entire 15.8 GB swap partition. Restarting the container resets it to ~300 MB and the cycle starts over.

The growth is strictly traffic-driven. A 23-hour idle control showed memory going down, not up, so this is not a background task.

To Reproduce

  1. Start the container and leave it idle until memory stabilises (~315 MB here).
  2. Sample memory.current from the container's cgroup every 10 s.
  3. Open the UI, don't type anything. Wait 90 s.
  4. Run one search. Let the answer finish. Wait 90 s.
  5. Ask a follow-up in the same conversation. Wait 90 s.
  6. Start a new conversation, run another search. Wait 90 s.
  7. Leave idle and keep sampling.

Memory rises as a clean step function, one step per action:

time action delta cumulative
22:04 open UI +73.7 MB +73.7
22:15 search #1 +52.0 MB +125.6
22:30 follow-up question +46.0 MB +174.7
22:32 new conversation + search #2 +13.5 MB +188.0
22:34 (GC pass) −24.6 MB +163.4

Baseline 314.9 MB → 478.4 MB. Peak 505.4 MB. Same PID throughout, no restart.

Expected behavior

Memory returns close to baseline once conversations are idle.

Instead, 12 minutes of complete inactivity after the last action gave back 0.2 MB:

22:34:47   478.4 MB
22:45:33   478.6 MB

Additional context

Idle control (this is the part that rules out caching and background jobs). 274 samples over 22.8 h with zero connections to the app: memory went from 386 MB down to 315 MB, i.e. it reclaims about 3 MB/h when untouched. Against ~40 MB per interaction, the break-even point is roughly one interaction every 13 hours — any real usage grows without bound.

Long-run growth, reproduced across two container lifetimes.

RSS swap total anon
day 1 1.4 GB 2.6 GB 4.0 GB
day 3 4.1 GB 9.0 GB 13.1 GB
day 4 2.2 GB 13.4 GB 15.6 GB

About 4.2 GB/day, monotonic, no plateau. A previous container instance hit 16.0 GB (6.4 GB RSS + 9.6 GB swap) before I restarted it — same pattern, so this isn't a one-off.

It is probably not the V8 JS heap. The process reached 15.6 GB of anonymous memory without ever throwing JavaScript heap out of memory, while Node's default old-space cap on this 15.4 GB host is around 4 GB. That points at external/native memory — Buffer/ArrayBuffer, or streams/sockets that are never closed — rather than retained JS objects.

It leaks even when search returns nothing. On my instance the bundled SearXNG currently fails every query (DuckDuckGo returns CAPTCHA, Wolfram Alpha times out), so every search above reported "Found 0 results" and no page was ever fetched or parsed. The retention happens anyway, which should narrow things down: the leaking path is upstream of search-result ingestion. I'd expect the per-interaction cost to be considerably higher when results are actually retrieved.

Environment

  • Image: itzcrazykns1337/vane@sha256:0b61bf0d4470e9f2a9c71f794b72fab6e5a612177172770684c158a461f6896e (currently tagged latest / main / full-latest, pushed 2026-09-01)
  • package.json version: 1.12.2
  • Node v24.5.0, Next.js 16.2.3
  • Docker on Debian, amd64 (Intel N100), 15.4 GB RAM
  • No container memory limit at the time of the incident

Workaround, in case it helps others. Setting mem_limit: 2g plus memswap_limit: 2g in the compose file confines the leak: the cgroup kills the container and restart: unless-stopped brings it back, instead of the leak consuming the host's entire swap.

Happy to run further instrumentation (heap snapshots via --heapsnapshot-signal, or a longer capture) if that would help.