Simulation scenarios to disable signal channel on resume (#2389)
* Add a simulation scenario to disconnect signal channel on resume - Requesting that scenario add that participant to a map with a timeout of 5 seconds. - If a resume (reconnect = 1) happens before the timeout, the signalling channel is closed immediately on resume. - There is a clean up worker which will remove entries from the map when they timout. - The participant is also removed from the map if the disconnect on resume is invoked once. * simulate disconnect signal on resume no messages * comment * comment * Close all retries * update deps * abort resume only if simulation applied * Revert SIP change
This commit is contained in:
@@ -77,7 +77,7 @@ require (
|
||||
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
|
||||
github.com/mdlayher/netlink v1.7.1 // indirect
|
||||
github.com/mdlayher/socket v0.4.0 // indirect
|
||||
github.com/nats-io/nats.go v1.31.0 // indirect
|
||||
github.com/nats-io/nats.go v1.32.0 // indirect
|
||||
github.com/nats-io/nkeys v0.4.7 // indirect
|
||||
github.com/nats-io/nuid v1.0.1 // indirect
|
||||
github.com/pion/datachannel v1.5.5 // indirect
|
||||
@@ -101,7 +101,7 @@ require (
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
golang.org/x/tools v0.17.0 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac // indirect
|
||||
google.golang.org/grpc v1.60.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
|
||||
@@ -161,8 +161,8 @@ github.com/mdlayher/socket v0.4.0 h1:280wsy40IC9M9q1uPGcLBwXpcTQDtoGwVt+BNoITxIw
|
||||
github.com/mdlayher/socket v0.4.0/go.mod h1:xxFqz5GRCUN3UEOm9CZqEJsAbe1C8OwSK46NlmWuVoc=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E=
|
||||
github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8=
|
||||
github.com/nats-io/nats.go v1.32.0 h1:Bx9BZS+aXYlxW08k8Gd3yR2s73pV5XSoAQUyp1Kwvp0=
|
||||
github.com/nats-io/nats.go v1.32.0/go.mod h1:Ubdu4Nh9exXdSz0RVWRFBbRfrbSxOYd26oF0wkWclB8=
|
||||
github.com/nats-io/nkeys v0.4.7 h1:RwNJbbIdYCoClSDNY7QVKZlyb/wfT6ugvFCiKy6vDvI=
|
||||
github.com/nats-io/nkeys v0.4.7/go.mod h1:kqXRgRDPlGy7nGaEDMuYzmiJCIAAWDK0IMBtDmGD0nc=
|
||||
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
|
||||
@@ -421,8 +421,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917 h1:6G8oQ016D88m1xAKljMlBOOGWDZkes4kMhgGFlf8WcQ=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240102182953-50ed04b92917/go.mod h1:xtjpI3tXFPP051KaWnhvxkiubL/6dJ18vLVf7q2pTOU=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac h1:nUQEQmH/csSvFECKYRv6HWEyypysidKl2I6Qpsglq/0=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240116215550-a9fa1716bcac/go.mod h1:daQN87bsDqDoe316QbbvX60nMoJQa4r6Ds0ZuoAe5yA=
|
||||
google.golang.org/grpc v1.60.1 h1:26+wFr+cNqSGFcOXcabYC0lUVJVRa2Sb2ortSK7VrEU=
|
||||
google.golang.org/grpc v1.60.1/go.mod h1:OlCHIeLYqSSsLi6i49B5QGdzaMZK9+M7LXN2FKz4eGM=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
|
||||
+97
-15
@@ -53,6 +53,8 @@ const (
|
||||
subscriberUpdateInterval = 3 * time.Second
|
||||
|
||||
dataForwardLoadBalanceThreshold = 20
|
||||
|
||||
simulateDisconnectSignalTimeout = 5 * time.Second
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -66,6 +68,11 @@ type broadcastOptions struct {
|
||||
immediate bool
|
||||
}
|
||||
|
||||
type disconnectSignalOnResumeNoMessages struct {
|
||||
expiry time.Time
|
||||
closedCount int
|
||||
}
|
||||
|
||||
type Room struct {
|
||||
lock sync.RWMutex
|
||||
|
||||
@@ -108,6 +115,10 @@ type Room struct {
|
||||
onParticipantChanged func(p types.LocalParticipant)
|
||||
onRoomUpdated func()
|
||||
onClose func()
|
||||
|
||||
simulationLock sync.Mutex
|
||||
disconnectSignalOnResumeParticipants map[livekit.ParticipantIdentity]time.Time
|
||||
disconnectSignalOnResumeNoMessagesParticipants map[livekit.ParticipantIdentity]*disconnectSignalOnResumeNoMessages
|
||||
}
|
||||
|
||||
type ParticipantOptions struct {
|
||||
@@ -132,21 +143,23 @@ func NewRoom(
|
||||
livekit.RoomName(room.Name),
|
||||
livekit.RoomID(room.Sid),
|
||||
),
|
||||
config: config,
|
||||
audioConfig: audioConfig,
|
||||
telemetry: telemetry,
|
||||
egressLauncher: egressLauncher,
|
||||
agentClient: agentClient,
|
||||
trackManager: NewRoomTrackManager(),
|
||||
serverInfo: serverInfo,
|
||||
participants: make(map[livekit.ParticipantIdentity]types.LocalParticipant),
|
||||
participantOpts: make(map[livekit.ParticipantIdentity]*ParticipantOptions),
|
||||
participantRequestSources: make(map[livekit.ParticipantIdentity]routing.MessageSource),
|
||||
hasPublished: make(map[livekit.ParticipantIdentity]bool),
|
||||
bufferFactory: buffer.NewFactoryOfBufferFactory(config.Receiver.PacketBufferSize),
|
||||
batchedUpdates: make(map[livekit.ParticipantIdentity]*livekit.ParticipantInfo),
|
||||
closed: make(chan struct{}),
|
||||
trailer: []byte(utils.RandomSecret()),
|
||||
config: config,
|
||||
audioConfig: audioConfig,
|
||||
telemetry: telemetry,
|
||||
egressLauncher: egressLauncher,
|
||||
agentClient: agentClient,
|
||||
trackManager: NewRoomTrackManager(),
|
||||
serverInfo: serverInfo,
|
||||
participants: make(map[livekit.ParticipantIdentity]types.LocalParticipant),
|
||||
participantOpts: make(map[livekit.ParticipantIdentity]*ParticipantOptions),
|
||||
participantRequestSources: make(map[livekit.ParticipantIdentity]routing.MessageSource),
|
||||
hasPublished: make(map[livekit.ParticipantIdentity]bool),
|
||||
bufferFactory: buffer.NewFactoryOfBufferFactory(config.Receiver.PacketBufferSize),
|
||||
batchedUpdates: make(map[livekit.ParticipantIdentity]*livekit.ParticipantInfo),
|
||||
closed: make(chan struct{}),
|
||||
trailer: []byte(utils.RandomSecret()),
|
||||
disconnectSignalOnResumeParticipants: make(map[livekit.ParticipantIdentity]time.Time),
|
||||
disconnectSignalOnResumeNoMessagesParticipants: make(map[livekit.ParticipantIdentity]*disconnectSignalOnResumeNoMessages),
|
||||
}
|
||||
|
||||
r.protoProxy = utils.NewProtoProxy[*livekit.Room](roomUpdateInterval, r.updateProto)
|
||||
@@ -175,6 +188,7 @@ func NewRoom(
|
||||
go r.audioUpdateWorker()
|
||||
go r.connectionQualityWorker()
|
||||
go r.changeUpdateWorker()
|
||||
go r.simulationCleanupWorker()
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -480,6 +494,26 @@ func (r *Room) ResumeParticipant(p types.LocalParticipant, requestSource routing
|
||||
|
||||
p.SetSignalSourceValid(true)
|
||||
|
||||
// check for simulated signal disconnect on resume before sending any signal response messages
|
||||
r.simulationLock.Lock()
|
||||
if state, ok := r.disconnectSignalOnResumeNoMessagesParticipants[p.Identity()]; ok {
|
||||
// WARNING: this uses knowledge that service layer tries internally
|
||||
simulated := false
|
||||
if time.Now().Before(state.expiry) {
|
||||
state.closedCount++
|
||||
p.CloseSignalConnection(types.SignallingCloseReasonDisconnectOnResumeNoMessages)
|
||||
simulated = true
|
||||
}
|
||||
if state.closedCount == 3 {
|
||||
delete(r.disconnectSignalOnResumeNoMessagesParticipants, p.Identity())
|
||||
}
|
||||
if simulated {
|
||||
r.simulationLock.Unlock()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
r.simulationLock.Unlock()
|
||||
|
||||
if err := p.HandleReconnectAndSendResponse(reason, &livekit.ReconnectResponse{
|
||||
IceServers: iceServers,
|
||||
ClientConfiguration: p.GetClientConfiguration(),
|
||||
@@ -495,6 +529,17 @@ func (r *Room) ResumeParticipant(p types.LocalParticipant, requestSource routing
|
||||
|
||||
_ = p.SendRoomUpdate(r.ToProto())
|
||||
p.ICERestart(nil)
|
||||
|
||||
// check for simulated signal disconnect on resume
|
||||
r.simulationLock.Lock()
|
||||
if timeout, ok := r.disconnectSignalOnResumeParticipants[p.Identity()]; ok {
|
||||
if time.Now().Before(timeout) {
|
||||
p.CloseSignalConnection(types.SignallingCloseReasonDisconnectOnResume)
|
||||
}
|
||||
delete(r.disconnectSignalOnResumeParticipants, p.Identity())
|
||||
}
|
||||
r.simulationLock.Unlock()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -849,6 +894,18 @@ func (r *Room) SimulateScenario(participant types.LocalParticipant, simulateScen
|
||||
r.Logger.Infow("simulating subscriber bandwidth end", "participant", participant.Identity())
|
||||
}
|
||||
participant.SetSubscriberChannelCapacity(scenario.SubscriberBandwidth)
|
||||
case *livekit.SimulateScenario_DisconnectSignalOnResume:
|
||||
participant.GetLogger().Infow("simulating disconnect signal on resume")
|
||||
r.simulationLock.Lock()
|
||||
r.disconnectSignalOnResumeParticipants[participant.Identity()] = time.Now().Add(simulateDisconnectSignalTimeout)
|
||||
r.simulationLock.Unlock()
|
||||
case *livekit.SimulateScenario_DisconnectSignalOnResumeNoMessages:
|
||||
participant.GetLogger().Infow("simulating disconnect signal on resume before sending any response messages")
|
||||
r.simulationLock.Lock()
|
||||
r.disconnectSignalOnResumeNoMessagesParticipants[participant.Identity()] = &disconnectSignalOnResumeNoMessages{
|
||||
expiry: time.Now().Add(simulateDisconnectSignalTimeout),
|
||||
}
|
||||
r.simulationLock.Unlock()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1338,6 +1395,31 @@ func (r *Room) connectionQualityWorker() {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Room) simulationCleanupWorker() {
|
||||
for {
|
||||
if r.IsClosed() {
|
||||
return
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
r.simulationLock.Lock()
|
||||
for identity, timeout := range r.disconnectSignalOnResumeParticipants {
|
||||
if now.After(timeout) {
|
||||
delete(r.disconnectSignalOnResumeParticipants, identity)
|
||||
}
|
||||
}
|
||||
|
||||
for identity, state := range r.disconnectSignalOnResumeNoMessagesParticipants {
|
||||
if now.After(state.expiry) {
|
||||
delete(r.disconnectSignalOnResumeNoMessagesParticipants, identity)
|
||||
}
|
||||
}
|
||||
r.simulationLock.Unlock()
|
||||
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Room) launchPublisherAgent(p types.Participant) {
|
||||
if p == nil || p.IsRecorder() || p.IsAgent() {
|
||||
return
|
||||
|
||||
@@ -187,7 +187,6 @@ func NewTransportManager(params TransportManagerParams) (*TransportManager, erro
|
||||
}
|
||||
|
||||
t.signalSourceValid.Store(true)
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -209,6 +209,8 @@ const (
|
||||
SignallingCloseReasonFullReconnectDataChannelError
|
||||
SignallingCloseReasonFullReconnectNegotiateFailed
|
||||
SignallingCloseReasonParticipantClose
|
||||
SignallingCloseReasonDisconnectOnResume
|
||||
SignallingCloseReasonDisconnectOnResumeNoMessages
|
||||
)
|
||||
|
||||
func (s SignallingCloseReason) String() string {
|
||||
@@ -231,6 +233,10 @@ func (s SignallingCloseReason) String() string {
|
||||
return "FULL_RECONNECT_NEGOTIATE_FAILED"
|
||||
case SignallingCloseReasonParticipantClose:
|
||||
return "PARTICIPANT_CLOSE"
|
||||
case SignallingCloseReasonDisconnectOnResume:
|
||||
return "DISCONNECT_ON_RESUME"
|
||||
case SignallingCloseReasonDisconnectOnResumeNoMessages:
|
||||
return "DISCONNECT_ON_RESUME_NO_MESSAGES"
|
||||
default:
|
||||
return fmt.Sprintf("%d", int(s))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user