Better tracking of signalling connection. (#1794)

* Better tracking of signalling connection.

- Reason for closing signaling channel.
- ConnectionID attached to request source/response sink

* Tests
This commit is contained in:
Raja Subramanian
2023-06-15 12:53:34 +05:30
committed by GitHub
parent 41bb1d8745
commit 12db469297
18 changed files with 275 additions and 49 deletions
+15 -5
View File
@@ -688,7 +688,7 @@ func (p *ParticipantImpl) Close(sendLeave bool, reason types.ParticipantCloseRea
p.updateState(livekit.ParticipantInfo_DISCONNECTED)
// ensure this is synchronized
p.CloseSignalConnection()
p.CloseSignalConnection(types.SignallingCloseReasonParticipantClose)
p.lock.RLock()
onClose := p.onClose
p.lock.RUnlock()
@@ -741,7 +741,7 @@ func (p *ParticipantImpl) MaybeStartMigration(force bool, onStart func()) bool {
onStart()
}
p.CloseSignalConnection()
p.CloseSignalConnection(types.SignallingCloseReasonMigration)
//
// On subscriber peer connection, remote side will try ICE on both
@@ -1349,7 +1349,7 @@ func (p *ParticipantImpl) setupDisconnectTimer() {
func (p *ParticipantImpl) onAnyTransportFailed() {
// clients support resuming of connections when websocket becomes disconnected
p.CloseSignalConnection()
p.CloseSignalConnection(types.SignallingCloseReasonTransportFailure)
// detect when participant has actually left.
p.setupDisconnectTimer()
@@ -2068,7 +2068,17 @@ func (p *ParticipantImpl) IssueFullReconnect(reason types.ParticipantCloseReason
},
},
})
p.CloseSignalConnection()
scr := types.SignallingCloseReasonUnknown
switch reason {
case types.ParticipantCloseReasonPublicationError:
scr = types.SignallingCloseReasonFullReconnectPublicationError
case types.ParticipantCloseReasonSubscriptionError:
scr = types.SignallingCloseReasonFullReconnectSubscriptionError
case types.ParticipantCloseReasonNegotiateFailed:
scr = types.SignallingCloseReasonFullReconnectNegotiateFailed
}
p.CloseSignalConnection(scr)
// on a full reconnect, no need to supervise this participant anymore
p.supervisor.Stop()
@@ -2101,7 +2111,7 @@ func (p *ParticipantImpl) onSubscriptionError(trackID livekit.TrackID, fatal boo
if p.params.ReconnectOnSubscriptionError && fatal {
p.params.Logger.Infow("issuing full reconnect on subscription error", "trackID", trackID)
p.IssueFullReconnect(types.ParticipantCloseReasonPublicationError)
p.IssueFullReconnect(types.ParticipantCloseReasonSubscriptionError)
}
}
+1 -1
View File
@@ -229,7 +229,7 @@ func TestOutOfOrderUpdates(t *testing.T) {
func TestDisconnectTiming(t *testing.T) {
t.Run("Negotiate doesn't panic after channel closed", func(t *testing.T) {
p := newParticipantForTest("test")
msg := routing.NewMessageChannel(routing.DefaultMessageChannelSize)
msg := routing.NewMessageChannel(livekit.ConnectionID("test"), routing.DefaultMessageChannelSize)
p.params.Sink = msg
go func() {
for msg := range msg.ReadChan() {
+3 -2
View File
@@ -11,6 +11,7 @@ import (
"github.com/livekit/psrpc"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/rtc/types"
)
func (p *ParticipantImpl) getResponseSink() routing.MessageSink {
@@ -280,10 +281,10 @@ func (p *ParticipantImpl) writeMessage(msg *livekit.SignalResponse) error {
}
// closes signal connection to notify client to resume/reconnect
func (p *ParticipantImpl) CloseSignalConnection() {
func (p *ParticipantImpl) CloseSignalConnection(reason types.SignallingCloseReason) {
sink := p.getResponseSink()
if sink != nil {
p.params.Logger.Infow("closing signal connection")
p.params.Logger.Infow("closing signal connection", "reason", reason, "connID", sink.ConnectionID())
sink.Close()
p.SetResponseSink(nil)
}
+1 -1
View File
@@ -400,7 +400,7 @@ func (r *Room) GetParticipantRequestSource(identity livekit.ParticipantIdentity)
func (r *Room) ResumeParticipant(p types.LocalParticipant, requestSource routing.MessageSource, responseSink routing.MessageSink, iceServers []*livekit.ICEServer, reason livekit.ReconnectReason) error {
r.ReplaceParticipantRequestSource(p.Identity(), requestSource)
// close previous sink, and link to new one
p.CloseSignalConnection()
p.CloseSignalConnection(types.SignallingCloseReasonResume)
p.SetResponseSink(responseSink)
p.SetSignalSourceValid(true)
+43 -2
View File
@@ -86,6 +86,7 @@ const (
ParticipantCloseReasonMigrationRequested
ParticipantCloseReasonOvercommitted
ParticipantCloseReasonPublicationError
ParticipantCloseReasonSubscriptionError
)
func (p ParticipantCloseReason) String() string {
@@ -130,6 +131,8 @@ func (p ParticipantCloseReason) String() string {
return "OVERCOMMITTED"
case ParticipantCloseReasonPublicationError:
return "PUBLICATION_ERROR"
case ParticipantCloseReasonSubscriptionError:
return "SUBSCRIPTION_ERROR"
default:
return fmt.Sprintf("%d", int(p))
}
@@ -160,7 +163,7 @@ func (p ParticipantCloseReason) ToDisconnectReason() livekit.DisconnectReason {
return livekit.DisconnectReason_SERVER_SHUTDOWN
case ParticipantCloseReasonOvercommitted:
return livekit.DisconnectReason_SERVER_SHUTDOWN
case ParticipantCloseReasonNegotiateFailed, ParticipantCloseReasonPublicationError:
case ParticipantCloseReasonNegotiateFailed, ParticipantCloseReasonPublicationError, ParticipantCloseReasonSubscriptionError:
return livekit.DisconnectReason_STATE_MISMATCH
default:
// the other types will map to unknown reason
@@ -170,6 +173,44 @@ func (p ParticipantCloseReason) ToDisconnectReason() livekit.DisconnectReason {
// ---------------------------------------------
type SignallingCloseReason int
const (
SignallingCloseReasonUnknown SignallingCloseReason = iota
SignallingCloseReasonMigration
SignallingCloseReasonResume
SignallingCloseReasonTransportFailure
SignallingCloseReasonFullReconnectPublicationError
SignallingCloseReasonFullReconnectSubscriptionError
SignallingCloseReasonFullReconnectNegotiateFailed
SignallingCloseReasonParticipantClose
)
func (s SignallingCloseReason) String() string {
switch s {
case SignallingCloseReasonUnknown:
return "UNKNOWN"
case SignallingCloseReasonMigration:
return "MIGRATION"
case SignallingCloseReasonResume:
return "RESUME"
case SignallingCloseReasonTransportFailure:
return "TRANSPORT_FAILURE"
case SignallingCloseReasonFullReconnectPublicationError:
return "FULL_RECONNECT_PUBLICATION_ERROR"
case SignallingCloseReasonFullReconnectSubscriptionError:
return "FULL_RECONNECT_SUBSCRIPTION_ERROR"
case SignallingCloseReasonFullReconnectNegotiateFailed:
return "FULL_RECONNECT_NEGOTIATE_FAILED"
case SignallingCloseReasonParticipantClose:
return "PARTICIPANT_CLOSE"
default:
return fmt.Sprintf("%d", int(s))
}
}
// ---------------------------------------------
//counterfeiter:generate . Participant
type Participant interface {
ID() livekit.ParticipantID
@@ -249,7 +290,7 @@ type LocalParticipant interface {
GetBufferFactory() *buffer.Factory
SetResponseSink(sink routing.MessageSink)
CloseSignalConnection()
CloseSignalConnection(reason SignallingCloseReason)
UpdateLastSeenSignal()
SetSignalSourceValid(valid bool)
@@ -131,9 +131,10 @@ type FakeLocalParticipant struct {
closeReturnsOnCall map[int]struct {
result1 error
}
CloseSignalConnectionStub func()
CloseSignalConnectionStub func(types.SignallingCloseReason)
closeSignalConnectionMutex sync.RWMutex
closeSignalConnectionArgsForCall []struct {
arg1 types.SignallingCloseReason
}
ConnectedAtStub func() time.Time
connectedAtMutex sync.RWMutex
@@ -1429,15 +1430,16 @@ func (fake *FakeLocalParticipant) CloseReturnsOnCall(i int, result1 error) {
}{result1}
}
func (fake *FakeLocalParticipant) CloseSignalConnection() {
func (fake *FakeLocalParticipant) CloseSignalConnection(arg1 types.SignallingCloseReason) {
fake.closeSignalConnectionMutex.Lock()
fake.closeSignalConnectionArgsForCall = append(fake.closeSignalConnectionArgsForCall, struct {
}{})
arg1 types.SignallingCloseReason
}{arg1})
stub := fake.CloseSignalConnectionStub
fake.recordInvocation("CloseSignalConnection", []interface{}{})
fake.recordInvocation("CloseSignalConnection", []interface{}{arg1})
fake.closeSignalConnectionMutex.Unlock()
if stub != nil {
fake.CloseSignalConnectionStub()
fake.CloseSignalConnectionStub(arg1)
}
}
@@ -1447,12 +1449,19 @@ func (fake *FakeLocalParticipant) CloseSignalConnectionCallCount() int {
return len(fake.closeSignalConnectionArgsForCall)
}
func (fake *FakeLocalParticipant) CloseSignalConnectionCalls(stub func()) {
func (fake *FakeLocalParticipant) CloseSignalConnectionCalls(stub func(types.SignallingCloseReason)) {
fake.closeSignalConnectionMutex.Lock()
defer fake.closeSignalConnectionMutex.Unlock()
fake.CloseSignalConnectionStub = stub
}
func (fake *FakeLocalParticipant) CloseSignalConnectionArgsForCall(i int) types.SignallingCloseReason {
fake.closeSignalConnectionMutex.RLock()
defer fake.closeSignalConnectionMutex.RUnlock()
argsForCall := fake.closeSignalConnectionArgsForCall[i]
return argsForCall.arg1
}
func (fake *FakeLocalParticipant) ConnectedAt() time.Time {
fake.connectedAtMutex.Lock()
ret, specificReturn := fake.connectedAtReturnsOnCall[len(fake.connectedAtArgsForCall)]