Fix: Return NotFoundErr instead of Unavailable when the participant does not exist in UpdateParticipant. (#3543)

* Check if Participant exists when update metadata

* Change Test cases

* type smuggle oss participant check into roomstore

* tidy

---------

Co-authored-by: Paul Wells <paulwe@gmail.com>
This commit is contained in:
Soungmin Son (Eddy)
2025-03-21 15:56:34 +09:00
committed by GitHub
parent 75d0e18e4a
commit 97fcb82a77
7 changed files with 27 additions and 6 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ require (
github.com/jxskiss/base62 v1.1.0
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1
github.com/livekit/mediatransportutil v0.0.0-20250310153736-45596af895b6
github.com/livekit/protocol v1.35.1-0.20250320161708-6d044a0462b3
github.com/livekit/protocol v1.35.1-0.20250321043517-157eda585c9a
github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126
github.com/mackerelio/go-osstat v0.2.5
github.com/magefile/mage v1.15.0
+2 -2
View File
@@ -170,8 +170,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD
github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
github.com/livekit/mediatransportutil v0.0.0-20250310153736-45596af895b6 h1:6ZhtnY9I9knfm3ieIPpznQSEU2rDECO8yliW/ANLQ7U=
github.com/livekit/mediatransportutil v0.0.0-20250310153736-45596af895b6/go.mod h1:36s+wwmU3O40IAhE+MjBWP3W71QRiEE9SfooSBvtBqY=
github.com/livekit/protocol v1.35.1-0.20250320161708-6d044a0462b3 h1:RsVnIuxnj3wRzWILhpnguyrq3vrK6Cccb762GpLH3Xg=
github.com/livekit/protocol v1.35.1-0.20250320161708-6d044a0462b3/go.mod h1:WrT/CYRxtMNOVUjnIPm5OjWtEkmreffTeE1PRZwlRg4=
github.com/livekit/protocol v1.35.1-0.20250321043517-157eda585c9a h1:NmBLyIS7rW9Jd/8WXLbo/Lk7ZuMgkwJDJiE1+ixGyDE=
github.com/livekit/protocol v1.35.1-0.20250321043517-157eda585c9a/go.mod h1:WrT/CYRxtMNOVUjnIPm5OjWtEkmreffTeE1PRZwlRg4=
github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126 h1:fzuYpAQbCid7ySPpQWWePfQOWUrs8x6dJ0T3Wl07n+Y=
github.com/livekit/psrpc v0.6.1-0.20250205181828-a0beed2e4126/go.mod h1:X5WtEZ7OnEs72Fi5/J+i0on3964F1aynQpCalcgMqRo=
github.com/mackerelio/go-osstat v0.2.5 h1:+MqTbZUhoIt4m8qzkVoXUJg1EuifwlAJSk4Yl2GXh+o=
+4
View File
@@ -52,6 +52,10 @@ type ServiceStore interface {
ListParticipants(ctx context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error)
}
type OSSServiceStore interface {
HasParticipant(context.Context, livekit.RoomName, livekit.ParticipantIdentity) (bool, error)
}
//counterfeiter:generate . EgressStore
type EgressStore interface {
StoreEgress(ctx context.Context, info *livekit.EgressInfo) error
+5
View File
@@ -153,6 +153,11 @@ func (s *LocalStore) LoadParticipant(_ context.Context, roomName livekit.RoomNam
return participant, nil
}
func (s *LocalStore) HasParticipant(ctx context.Context, roomName livekit.RoomName, identity livekit.ParticipantIdentity) (bool, error) {
p, err := s.LoadParticipant(ctx, roomName, identity)
return p != nil, utils.ScreenError(err, ErrParticipantNotFound)
}
func (s *LocalStore) ListParticipants(_ context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error) {
s.lock.RLock()
defer s.lock.RUnlock()
+5
View File
@@ -314,6 +314,11 @@ func (s *RedisStore) LoadParticipant(_ context.Context, roomName livekit.RoomNam
return &pi, nil
}
func (s *RedisStore) HasParticipant(ctx context.Context, roomName livekit.RoomName, identity livekit.ParticipantIdentity) (bool, error) {
p, err := s.LoadParticipant(ctx, roomName, identity)
return p != nil, utils.ScreenError(err, ErrParticipantNotFound)
}
func (s *RedisStore) ListParticipants(_ context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error) {
key := RoomParticipantsPrefix + string(roomName)
items, err := s.rc.HVals(s.ctx, key).Result()
+9
View File
@@ -238,6 +238,15 @@ func (s *RoomService) UpdateParticipant(ctx context.Context, req *livekit.Update
return nil, twirpAuthError(err)
}
if os, ok := s.roomStore.(OSSServiceStore); ok {
found, err := os.HasParticipant(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity))
if err != nil {
return nil, err
} else if !found {
return nil, ErrParticipantNotFound
}
}
res, err := s.participantClient.UpdateParticipant(ctx, s.topicFormatter.ParticipantTopic(ctx, livekit.RoomName(req.Room), livekit.ParticipantIdentity(req.Identity)), req)
RecordResponse(ctx, res)
return res, err
+1 -3
View File
@@ -356,9 +356,7 @@ func TestSingleNodeUpdateParticipant(t *testing.T) {
require.Error(t, err)
var twErr twirp.Error
require.True(t, errors.As(err, &twErr))
// Note: for Cloud this would return 404, currently we are not able to differentiate between
// non-existent participant vs server being unavailable in OSS
require.Equal(t, twirp.Unavailable, twErr.Code())
require.Equal(t, twirp.NotFound, twErr.Code())
})
}