Catching a few more races reported by go test -race ./... (#713)
* Fix a few more races * Make sure room store on leave has correct count * Revert logger change to reduce diff
This commit is contained in:
+15
-13
@@ -239,6 +239,7 @@ func (r *RoomManager) StartSession(
|
||||
rtcConf.SetBufferFactory(room.GetBufferFactory())
|
||||
sid := livekit.ParticipantID(utils.NewGuid(utils.ParticipantPrefix))
|
||||
pLogger := rtc.LoggerWithParticipant(room.Logger, pi.Identity, sid)
|
||||
protoRoom := room.ToProto()
|
||||
participant, err = rtc.NewParticipant(rtc.ParticipantParams{
|
||||
Identity: pi.Identity,
|
||||
Name: pi.Name,
|
||||
@@ -251,7 +252,7 @@ func (r *RoomManager) StartSession(
|
||||
Telemetry: r.telemetry,
|
||||
PLIThrottleConfig: r.config.RTC.PLIThrottle,
|
||||
CongestionControlConfig: r.config.RTC.CongestionControl,
|
||||
EnabledCodecs: room.Room.EnabledCodecs,
|
||||
EnabledCodecs: protoRoom.EnabledCodecs,
|
||||
Grants: pi.Grants,
|
||||
Logger: pLogger,
|
||||
ClientConf: clientConf,
|
||||
@@ -266,7 +267,7 @@ func (r *RoomManager) StartSession(
|
||||
opts := rtc.ParticipantOptions{
|
||||
AutoSubscribe: pi.AutoSubscribe,
|
||||
}
|
||||
if err = room.Join(participant, &opts, r.iceServersForRoom(room.Room), r.currentNode.Region); err != nil {
|
||||
if err = room.Join(participant, &opts, r.iceServersForRoom(protoRoom), r.currentNode.Region); err != nil {
|
||||
pLogger.Errorw("could not join room", err)
|
||||
_ = participant.Close(true)
|
||||
return err
|
||||
@@ -275,9 +276,9 @@ func (r *RoomManager) StartSession(
|
||||
pLogger.Errorw("could not store participant", err)
|
||||
}
|
||||
|
||||
updateParticipantCount := func() {
|
||||
updateParticipantCount := func(proto *livekit.Room) {
|
||||
if !participant.Hidden() {
|
||||
err = r.roomStore.StoreRoom(ctx, room.Room)
|
||||
err = r.roomStore.StoreRoom(ctx, proto)
|
||||
if err != nil {
|
||||
logger.Errorw("could not store room", err)
|
||||
}
|
||||
@@ -285,18 +286,19 @@ func (r *RoomManager) StartSession(
|
||||
}
|
||||
|
||||
// update room store with new numParticipants
|
||||
updateParticipantCount()
|
||||
updateParticipantCount(protoRoom)
|
||||
|
||||
clientMeta := &livekit.AnalyticsClientMeta{Region: r.currentNode.Region, Node: r.currentNode.Id}
|
||||
r.telemetry.ParticipantJoined(ctx, room.Room, participant.ToProto(), pi.Client, clientMeta)
|
||||
r.telemetry.ParticipantJoined(ctx, protoRoom, participant.ToProto(), pi.Client, clientMeta)
|
||||
participant.OnClose(func(p types.LocalParticipant, disallowedSubscriptions map[livekit.TrackID]livekit.ParticipantID) {
|
||||
if err := r.roomStore.DeleteParticipant(ctx, roomName, p.Identity()); err != nil {
|
||||
pLogger.Errorw("could not delete participant", err)
|
||||
}
|
||||
|
||||
// update room store with new numParticipants
|
||||
updateParticipantCount()
|
||||
r.telemetry.ParticipantLeft(ctx, room.Room, p.ToProto())
|
||||
proto := room.ToProto()
|
||||
updateParticipantCount(proto)
|
||||
r.telemetry.ParticipantLeft(ctx, proto, p.ToProto())
|
||||
|
||||
room.RemoveDisallowedSubscriptions(p, disallowedSubscriptions)
|
||||
})
|
||||
@@ -345,7 +347,7 @@ func (r *RoomManager) getOrCreateRoom(ctx context.Context, roomName livekit.Room
|
||||
newRoom := rtc.NewRoom(ri, *r.rtcConfig, &r.config.Audio, r.telemetry)
|
||||
|
||||
newRoom.OnClose(func() {
|
||||
r.telemetry.RoomEnded(ctx, newRoom.Room)
|
||||
r.telemetry.RoomEnded(ctx, newRoom.ToProto())
|
||||
if err := r.DeleteRoom(ctx, roomName); err != nil {
|
||||
logger.Errorw("could not delete room", err)
|
||||
}
|
||||
@@ -354,7 +356,7 @@ func (r *RoomManager) getOrCreateRoom(ctx context.Context, roomName livekit.Room
|
||||
})
|
||||
|
||||
newRoom.OnMetadataUpdate(func(metadata string) {
|
||||
if err := r.roomStore.StoreRoom(ctx, newRoom.Room); err != nil {
|
||||
if err := r.roomStore.StoreRoom(ctx, newRoom.ToProto()); err != nil {
|
||||
logger.Errorw("could not handle metadata update", err)
|
||||
}
|
||||
})
|
||||
@@ -373,7 +375,7 @@ func (r *RoomManager) getOrCreateRoom(ctx context.Context, roomName livekit.Room
|
||||
|
||||
newRoom.Hold()
|
||||
|
||||
r.telemetry.RoomStarted(ctx, newRoom.Room)
|
||||
r.telemetry.RoomStarted(ctx, newRoom.ToProto())
|
||||
|
||||
return newRoom, nil
|
||||
}
|
||||
@@ -384,8 +386,8 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.LocalPa
|
||||
logger.Debugw("RTC session finishing",
|
||||
"participant", participant.Identity(),
|
||||
"pID", participant.ID(),
|
||||
"room", room.Room.Name,
|
||||
"roomID", room.Room.Sid,
|
||||
"room", room.Name(),
|
||||
"roomID", room.ID(),
|
||||
)
|
||||
_ = participant.Close(true)
|
||||
requestSource.Close()
|
||||
|
||||
Reference in New Issue
Block a user