Skip to content

Commit b0ff47c

Browse files
committed
Fix deadlock from SSE Events Channel
If client doesn't open a SSE Events Channel this will deadlock and it holds the global lock
1 parent db90e73 commit b0ff47c

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

internal/webrtc/sessions/manager/manager.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ func (manager *SessionManager) UpdateProfile(profile *authorization.PersonalProf
180180

181181
// Get Session by id
182182
func (manager *SessionManager) GetWhepSessionById(sessionId string) (whep *whep.WhepSession, foundSession bool) {
183-
184183
manager.sessionsLock.RLock()
185184
defer manager.sessionsLock.RUnlock()
186185

internal/webrtc/sessions/session/routines.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,14 @@ func (session *Session) hostStatusLoop() {
142142
} else if session.Host.Load() != nil {
143143

144144
status := session.GetSessionStatsEvent()
145+
145146
session.WhepSessionsLock.RLock()
146-
for _, whep := range session.WhepSessions {
147-
whep.SseEventsChannel <- status
147+
for _, whepSession := range session.WhepSessions {
148+
select {
149+
case whepSession.SseEventsChannel <- status:
150+
default:
151+
log.Println("Session.Host.HostStatusLoop: SSE channel full, skipping", whepSession.SessionId)
152+
}
148153
}
149154
session.WhepSessionsLock.RUnlock()
150155

0 commit comments

Comments
 (0)