Close websocket connection upon join failure (#458)
* Close websocket connection on join failure to avoid hang * fix auto creation bug
This commit is contained in:
+1
-1
@@ -181,7 +181,7 @@ func (r *Room) Join(participant types.LocalParticipant, opts *ParticipantOptions
|
|||||||
return ErrAlreadyJoined
|
return ErrAlreadyJoined
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Room.MaxParticipants > 0 && int(r.Room.MaxParticipants) == len(r.participants) {
|
if r.Room.MaxParticipants > 0 && len(r.participants) >= int(r.Room.MaxParticipants) {
|
||||||
prometheus.ServiceOperationCounter.WithLabelValues("participant_join", "error", "max_exceeded").Add(1)
|
prometheus.ServiceOperationCounter.WithLabelValues("participant_join", "error", "max_exceeded").Add(1)
|
||||||
return ErrMaxParticipantsExceeded
|
return ErrMaxParticipantsExceeded
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -260,6 +260,7 @@ func (r *RoomManager) StartSession(ctx context.Context, roomName livekit.RoomNam
|
|||||||
}
|
}
|
||||||
if err = room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
|
if err = room.Join(participant, &opts, r.iceServersForRoom(room.Room)); err != nil {
|
||||||
pLogger.Errorw("could not join room", err)
|
pLogger.Errorw("could not join room", err)
|
||||||
|
_ = participant.Close(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err = r.roomStore.StoreParticipant(ctx, roomName, participant.ToProto()); err != nil {
|
if err = r.roomStore.StoreParticipant(ctx, roomName, participant.ToProto()); err != nil {
|
||||||
|
|||||||
@@ -151,8 +151,10 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
_, err := s.store.LoadRoom(context.Background(), roomName)
|
_, err := s.store.LoadRoom(context.Background(), roomName)
|
||||||
if err == ErrRoomNotFound {
|
if err == ErrRoomNotFound {
|
||||||
handleError(w, 404, err.Error())
|
handleError(w, 404, err.Error())
|
||||||
|
return
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
handleError(w, 500, err.Error())
|
handleError(w, 500, err.Error())
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -361,6 +361,11 @@ func TestAutoCreate(t *testing.T) {
|
|||||||
token := joinToken(testRoom, "start-before-create")
|
token := joinToken(testRoom, "start-before-create")
|
||||||
_, err := testclient.NewWebSocketConn(fmt.Sprintf("ws://localhost:%d", defaultServerPort), token, nil)
|
_, err := testclient.NewWebSocketConn(fmt.Sprintf("ws://localhost:%d", defaultServerPort), token, nil)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
|
// second join should also fail
|
||||||
|
token = joinToken(testRoom, "start-before-create-2")
|
||||||
|
_, err = testclient.NewWebSocketConn(fmt.Sprintf("ws://localhost:%d", defaultServerPort), token, nil)
|
||||||
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("join with explicit createRoom", func(t *testing.T) {
|
t.Run("join with explicit createRoom", func(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user