You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Unchecked RTP packet forwarding to non-connected WebRTC peers in UdpSocketManager causes high CPU churn and event-loop lag #511
In src/server/signalling/handlers/udpSocket.ts (lines 100-113), the UDP message handler forwards high-frequency incoming RTP packets (typically 2,000 to 4,000 packets per second from GStreamer) to all sessions registered in this.clients:
socket.on("message",(msg)=>{for(constclientofthis.clients.values()){try{if(trackKind==="video"){client.videoTrack.writeRtp(msg)}else{client.audioTrack.writeRtp(msg)}client.bytesSent+=msg.length}catch{// Individual track write errors are non-fatal}}})
However, a newly initiated session is added to this.clients during handleOffer, well before DTLS and SRTP negotiation finish (pc.connectionState is "new" or "connecting"). Similarly, disconnected sessions remain in this.clients during their 10-second grace timer (pc.connectionState is "disconnected" or "failed").
Because socket.on("message") iterates over this.clients.values() unconditionally without verifying whether client.pc.connectionState === "connected":
It attempts to call writeRtp(msg) thousands of times per second on sessions whose SRTP cipher contexts are uninitialized or closed.
This throws and catches thousands of internal exceptions per second inside the Node.js event loop, creating heavy CPU churn.
This event loop congestion induces noticeable latency spikes on real-time WebRTC DataChannel input message processing and unnecessarily inflates bytesSent on dead or half-open connections.
Steps to Reproduce
Start the Rein desktop server with GStreamer streaming enabled (npm run dev).
Observe server process CPU utilization when a client connects or during session renegotiation/disconnect grace periods.
Inspect UdpSocketManager.createRtpSocket: for every received UDP datagram (2,000-4,000/s), client.videoTrack.writeRtp(msg) is invoked unconditionally even if client.pc.connectionState is "new", "connecting", "disconnected", or "failed".
Expected Behavior
UdpSocketManager should verify if (client.pc.connectionState !== "connected") continue before attempting track writes, ensuring packets are dispatched only to fully established peer connections.
Activity
github-actions commentedon Nov 22, 2026
Discussions are carried on Discord.
Instead of commenting here, go to the Discord channel.
macOS and macOS-related issues are not supported at the moment. We are looking for funding to support macOS and would appreciate sponsorships.
If you find this project useful, a GitHub star would be appreciated.