Fix memory leak in WebSocket handler during high-load events

● Open ⚡ High Priority 🏷️ Bug 📁 src/core/ws
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:

  1. Run load-test --conns 10000 --duration 300s
  2. Monitor via git monitor --heap
  3. 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
Aisha Rodriguez 2 hours ago
I've patched the event listener teardown. The leak was caused by unbound onMessage callbacks retaining references to closed frames. Attached the benchmark diff showing a 94% reduction in heap retention.
MK
Marcus Klein 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.