mirror of
https://github.com/livekit/livekit.git
synced 2026-05-12 21:05:26 +00:00
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:
committed by
GitHub
parent
75d0e18e4a
commit
97fcb82a77
@@ -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
|
||||
|
||||
@@ -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=
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user