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:
+10
-12
@@ -359,7 +359,7 @@ func (r *RoomManager) StartSession(
|
||||
),
|
||||
pi.ReconnectReason,
|
||||
); err != nil {
|
||||
logger.Warnw("could not resume participant", err, "participant", pi.Identity)
|
||||
participant.GetLogger().Warnw("could not resume participant", err)
|
||||
return err
|
||||
}
|
||||
r.telemetry.ParticipantResumed(ctx, room.ToProto(), participant.ToProto(), livekit.NodeID(r.currentNode.Id), pi.ReconnectReason)
|
||||
@@ -394,10 +394,16 @@ func (r *RoomManager) StartSession(
|
||||
return errors.New("could not restart participant")
|
||||
}
|
||||
|
||||
logger.Debugw("starting RTC session",
|
||||
sid := livekit.ParticipantID(guid.New(utils.ParticipantPrefix))
|
||||
pLogger := rtc.LoggerWithParticipant(
|
||||
rtc.LoggerWithRoom(logger.GetLogger(), room.Name(), room.ID()),
|
||||
pi.Identity,
|
||||
sid,
|
||||
false,
|
||||
)
|
||||
pLogger.Infow("starting RTC session",
|
||||
"room", room.Name(),
|
||||
"nodeID", r.currentNode.Id,
|
||||
"participant", pi.Identity,
|
||||
"clientInfo", logger.Proto(pi.Client),
|
||||
"reconnect", pi.Reconnect,
|
||||
"reconnectReason", pi.ReconnectReason,
|
||||
@@ -413,12 +419,6 @@ func (r *RoomManager) StartSession(
|
||||
if pi.DisableICELite {
|
||||
rtcConf.SettingEngine.SetLite(false)
|
||||
}
|
||||
sid := livekit.ParticipantID(guid.New(utils.ParticipantPrefix))
|
||||
pLogger := rtc.LoggerWithParticipant(
|
||||
rtc.LoggerWithRoom(logger.GetLogger(), room.Name(), room.ID()),
|
||||
pi.Identity,
|
||||
sid,
|
||||
false)
|
||||
// default allow forceTCP
|
||||
allowFallback := true
|
||||
if r.config.RTC.AllowTCPFallback != nil {
|
||||
@@ -546,7 +546,7 @@ func (r *RoomManager) StartSession(
|
||||
participant.OnClaimsChanged(func(participant types.LocalParticipant) {
|
||||
pLogger.Debugw("refreshing client token after claims change")
|
||||
if err := r.refreshToken(participant); err != nil {
|
||||
logger.Errorw("could not refresh token", err)
|
||||
pLogger.Errorw("could not refresh token", err)
|
||||
}
|
||||
})
|
||||
participant.OnICEConfigChanged(func(participant types.LocalParticipant, iceConfig *livekit.ICEConfig) {
|
||||
@@ -696,8 +696,6 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
|
||||
pLogger.Errorw("could not refresh token", err, "connID", requestSource.ConnectionID())
|
||||
}
|
||||
case obj := <-requestSource.ReadChan():
|
||||
// In single node mode, the request source is directly tied to the signal message channel
|
||||
// this means ICE restart isn't possible in single node mode
|
||||
if obj == nil {
|
||||
if room.GetParticipantRequestSource(participant.Identity()) == requestSource {
|
||||
participant.HandleSignalSourceClose()
|
||||
|
||||
@@ -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{})
|
||||
|
||||
Reference in New Issue
Block a user