Fix memory leak in WebSocket handler during high-load events
Description
Under sustained load (>10k concurrent connections), the WebSocket handler fails to release buffer memory after client disconnection. This results in a steady ~2.4MB/minute memory climb until the process OOMs.
Reproduction steps:
- Run
load-test --conns 10000 --duration 300s - Monitor via
git monitor --heap - Observe retained byte buffers in the event loop
- const buffer = await socket.read();
+ const buffer = socket.createStream();
// Explicitly drain on close event
+ socket.on('close', () => buffer.destroy());
Related to #1388 and platform scaling benchmarks.
AR
MK
5 hours ago
LGTM. Can we add a stress test to the CI pipeline before merging? The last time we skipped this, it caused the staging incident on Friday.
onMessagecallbacks retaining references to closed frames. Attached the benchmark diff showing a 94% reduction in heap retention.