Recreate stats worker on resume if needed. (#2982)

* Ref count the stats worker.

NOTE: Don't liek this much, but wanted to open this get some 👀 on
this and get feedback.

There are two entities, one for counting signal bytes and another for
media stats. They both send `ParticipantJoined` and `ParticipantLeft`
event.

In the case of a participant resume, as the old web socket
connection is closed, that triggers a signal stats counter close. That
would call `ParticipantLeft` and that would close the stats worker.

The closed stats worker got reaped in `FlushStats` after three minutes.

So, all events after that did not have a worker and hence went
unreported including missing participant_left webhook because it relied
on checking if a participant was ever connected and that needed to check
the worker state.

Using a ref count to keep track of join/leaves. And not close the worker
until ref count goes down to 0.

* create a stats worker on resume

* revert incorrect changes

* transfer connected state

* transfer connected state when creating worker

* resolve participant on a resume
This commit is contained in:
Raja Subramanian
2024-09-06 23:58:03 +05:30
committed by GitHub
parent 95fa55eb5d
commit bec7453a1f
4 changed files with 51 additions and 14 deletions
+6
View File
@@ -276,6 +276,12 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
signalStats.ResolveRoom(join.GetRoom())
signalStats.ResolveParticipant(join.GetParticipant())
}
if pi.Reconnect && pi.ID != "" {
signalStats.ResolveParticipant(&livekit.ParticipantInfo{
Sid: string(pi.ID),
Identity: string(pi.Identity),
})
}
closedByClient := atomic.NewBool(false)
done := make(chan struct{})