fix(rtc): drop late SFU subscriber offers when peer connection is closed#240
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughA single defensive guard is added to ChangesSubscriber SDP Offer Late-Arrival Guard
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
e19c479 to
f43c97d
Compare
`_on_subscriber_offer` unconditionally called `setRemoteDescription` on `subscriber_pc`, so an offer that arrived after the connection was torn down raised `InvalidStateError: Cannot handle offer in signaling state "closed"`. The exception propagated through the pyee error path and killed the session. Reproduces reliably under load: when the asyncio loop falls behind (e.g. several concurrent agent sessions on one pod), session cleanup and a late SFU renegotiation race, the offer arrives at a closed peer connection, and the resulting exception drops the agent's remaining sessions. Guard the handler: if `subscriber_pc` is missing or `signalingState` is `"closed"`, drop the offer and log at debug level — there is nothing to negotiate with a closed connection.
f43c97d to
b1442bf
Compare
Why
_on_subscriber_offerunconditionally callssetRemoteDescriptiononsubscriber_pc. If an offer arrives after the connection has been torn down (slow asyncio loop under load, SFU sending a late renegotiation), aiortc raisesInvalidStateError: Cannot handle offer in signaling state "closed". The exception then propagates through the pyee error path and kills the surrounding session.Reproduces reliably under load: when several concurrent agent sessions run on one pod and the asyncio loop falls behind, session cleanup and a late SFU offer race. We've been observing this pattern on a production deploy that runs multiple agent sessions per pod — each unhandled error visibly drops sessions for users mid-call.
Changes
_on_subscriber_offer, guard against a missing or closedsubscriber_pc: drop the offer and log at debug level. Nothing to negotiate with a closed connection.Summary by CodeRabbit