Log ICE reconnected. (#2999)

To increase visibility of ICE reconnect, logging reconnected at Infow
level. Otherwise, it is hard to see if an ICE restart finished
successfully.

Also, cleaning up ICEConnectionDetails a bit. Just separate out
read-only fields into its own struct and use it for read-only export.
This commit is contained in:
Raja Subramanian
2024-09-12 13:16:41 +05:30
committed by GitHub
parent ce663f9550
commit 1b5bb4dddc
7 changed files with 120 additions and 84 deletions
+14 -14
View File
@@ -455,10 +455,10 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
meta := &livekit.AnalyticsClientMeta{ meta := &livekit.AnalyticsClientMeta{
ClientConnectTime: uint32(time.Since(p.ConnectedAt()).Milliseconds()), ClientConnectTime: uint32(time.Since(p.ConnectedAt()).Milliseconds()),
} }
cds := p.GetICEConnectionDetails() infos := p.GetICEConnectionInfo()
for _, cd := range cds { for _, info := range infos {
if cd.Type != types.ICEConnectionTypeUnknown { if info.Type != types.ICEConnectionTypeUnknown {
meta.ConnectionType = string(cd.Type) meta.ConnectionType = string(info.Type)
break break
} }
} }
@@ -469,7 +469,7 @@ func (r *Room) Join(participant types.LocalParticipant, requestSource routing.Me
false, false,
) )
p.GetLogger().Infow("participant active", connectionDetailsFields(cds)...) p.GetLogger().Infow("participant active", connectionDetailsFields(infos)...)
} else if state == livekit.ParticipantInfo_DISCONNECTED { } else if state == livekit.ParticipantInfo_DISCONNECTED {
// remove participant from room // remove participant from room
// participant should already be closed and have a close reason, so NONE is fine here // participant should already be closed and have a close reason, so NONE is fine here
@@ -695,7 +695,7 @@ func (r *Room) RemoveParticipant(identity livekit.ParticipantIdentity, pID livek
r.protoProxy.MarkDirty(immediateChange) r.protoProxy.MarkDirty(immediateChange)
if !p.HasConnected() { if !p.HasConnected() {
fields := append(connectionDetailsFields(p.GetICEConnectionDetails()), fields := append(connectionDetailsFields(p.GetICEConnectionInfo()),
"reason", reason.String(), "reason", reason.String(),
) )
p.GetLogger().Infow("removing participant without connection", fields...) p.GetLogger().Infow("removing participant without connection", fields...)
@@ -1804,12 +1804,12 @@ func IsCloseNotifySkippable(closeReason types.ParticipantCloseReason) bool {
return closeReason == types.ParticipantCloseReasonDuplicateIdentity return closeReason == types.ParticipantCloseReasonDuplicateIdentity
} }
func connectionDetailsFields(cds []*types.ICEConnectionDetails) []interface{} { func connectionDetailsFields(infos []*types.ICEConnectionInfo) []interface{} {
var fields []interface{} var fields []interface{}
connectionType := types.ICEConnectionTypeUnknown connectionType := types.ICEConnectionTypeUnknown
for _, cd := range cds { for _, info := range infos {
candidates := make([]string, 0, len(cd.Remote)+len(cd.Local)) candidates := make([]string, 0, len(info.Remote)+len(info.Local))
for _, c := range cd.Local { for _, c := range info.Local {
cStr := "[local]" cStr := "[local]"
if c.Selected { if c.Selected {
cStr += "[selected]" cStr += "[selected]"
@@ -1822,7 +1822,7 @@ func connectionDetailsFields(cds []*types.ICEConnectionDetails) []interface{} {
cStr += " " + c.Local.String() cStr += " " + c.Local.String()
candidates = append(candidates, cStr) candidates = append(candidates, cStr)
} }
for _, c := range cd.Remote { for _, c := range info.Remote {
cStr := "[remote]" cStr := "[remote]"
if c.Selected { if c.Selected {
cStr += "[selected]" cStr += "[selected]"
@@ -1836,10 +1836,10 @@ func connectionDetailsFields(cds []*types.ICEConnectionDetails) []interface{} {
candidates = append(candidates, cStr) candidates = append(candidates, cStr)
} }
if len(candidates) > 0 { if len(candidates) > 0 {
fields = append(fields, fmt.Sprintf("%sCandidates", strings.ToLower(cd.Transport.String())), candidates) fields = append(fields, fmt.Sprintf("%sCandidates", strings.ToLower(info.Transport.String())), candidates)
} }
if cd.Type != types.ICEConnectionTypeUnknown { if info.Type != types.ICEConnectionTypeUnknown {
connectionType = cd.Type connectionType = info.Type
} }
} }
fields = append(fields, "connectionType", connectionType) fields = append(fields, "connectionType", connectionType)
+31 -3
View File
@@ -35,6 +35,7 @@ import (
"github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3"
"github.com/pkg/errors" "github.com/pkg/errors"
"go.uber.org/atomic" "go.uber.org/atomic"
"go.uber.org/zap/zapcore"
lkinterceptor "github.com/livekit/mediatransportutil/pkg/interceptor" lkinterceptor "github.com/livekit/mediatransportutil/pkg/interceptor"
lktwcc "github.com/livekit/mediatransportutil/pkg/twcc" lktwcc "github.com/livekit/mediatransportutil/pkg/twcc"
@@ -131,6 +132,30 @@ func (e event) String() string {
// ------------------------------------------------------- // -------------------------------------------------------
type wrappedICECandidatePairLogger struct {
pair *webrtc.ICECandidatePair
}
func (w wrappedICECandidatePairLogger) MarshalLogObject(e zapcore.ObjectEncoder) error {
if w.pair == nil {
return nil
}
if w.pair.Local != nil {
e.AddString("localProtocol", w.pair.Local.Protocol.String())
e.AddString("localCandidateType", w.pair.Local.Typ.String())
e.AddString("localAdddress", w.pair.Local.Address)
e.AddUint16("localPort", w.pair.Local.Port)
}
if w.pair.Remote != nil {
e.AddString("remoteProtocol", w.pair.Remote.Protocol.String())
e.AddString("remoteCandidateType", w.pair.Remote.Typ.String())
}
return nil
}
// -------------------------------------------------------------------
type SimulcastTrackInfo struct { type SimulcastTrackInfo struct {
Mid string Mid string
Rid string Rid string
@@ -617,7 +642,7 @@ func (t *PCTransport) handleConnectionFailed(forceShortConn bool) {
isShort, duration = t.IsShortConnection(time.Now()) isShort, duration = t.IsShortConnection(time.Now())
if isShort { if isShort {
pair, err := t.getSelectedPair() pair, err := t.getSelectedPair()
t.params.Logger.Debugw("short ICE connection", "error", err, "pair", pair, "duration", duration) t.params.Logger.Debugw("short ICE connection", "error", err, "pair", wrappedICECandidatePairLogger{pair}, "duration", duration)
} }
} }
@@ -653,6 +678,9 @@ func (t *PCTransport) onPeerConnectionStateChange(state webrtc.PeerConnectionSta
t.params.Handler.OnInitialConnected() t.params.Handler.OnInitialConnected()
t.maybeNotifyFullyEstablished() t.maybeNotifyFullyEstablished()
} else {
pair, err := t.getSelectedPair()
t.params.Logger.Infow("ice reconnected", "error", err, "pair", wrappedICECandidatePairLogger{pair})
} }
case webrtc.PeerConnectionStateFailed: case webrtc.PeerConnectionStateFailed:
t.clearConnTimer() t.clearConnTimer()
@@ -911,8 +939,8 @@ func (t *PCTransport) HasEverConnected() bool {
return !t.firstConnectedAt.IsZero() return !t.firstConnectedAt.IsZero()
} }
func (t *PCTransport) GetICEConnectionDetails() *types.ICEConnectionDetails { func (t *PCTransport) GetICEConnectionInfo() *types.ICEConnectionInfo {
return t.connectionDetails return t.connectionDetails.GetInfo()
} }
func (t *PCTransport) WriteRTCP(pkts []rtcp.Packet) error { func (t *PCTransport) WriteRTCP(pkts []rtcp.Packet) error {
+6 -6
View File
@@ -482,15 +482,15 @@ func (t *TransportManager) SubscriberAsPrimary() bool {
return t.params.SubscriberAsPrimary return t.params.SubscriberAsPrimary
} }
func (t *TransportManager) GetICEConnectionDetails() []*types.ICEConnectionDetails { func (t *TransportManager) GetICEConnectionInfo() []*types.ICEConnectionInfo {
details := make([]*types.ICEConnectionDetails, 0, 2) infos := make([]*types.ICEConnectionInfo, 0, 2)
for _, pc := range []*PCTransport{t.publisher, t.subscriber} { for _, pc := range []*PCTransport{t.publisher, t.subscriber} {
cd := pc.GetICEConnectionDetails() info := pc.GetICEConnectionInfo()
if cd.HasCandidates() { if info.HasCandidates() {
details = append(details, cd.Clone()) infos = append(infos, info)
} }
} }
return details return infos
} }
func (t *TransportManager) getTransport(isPrimary bool) *PCTransport { func (t *TransportManager) getTransport(isPrimary bool) *PCTransport {
+25 -19
View File
@@ -47,43 +47,49 @@ type ICECandidateExtended struct {
Trickle bool Trickle bool
} }
type ICEConnectionDetails struct { // --------------------------------------------
type ICEConnectionInfo struct {
Local []*ICECandidateExtended Local []*ICECandidateExtended
Remote []*ICECandidateExtended Remote []*ICECandidateExtended
Transport livekit.SignalTarget Transport livekit.SignalTarget
Type ICEConnectionType Type ICEConnectionType
lock sync.Mutex }
logger logger.Logger
func (i *ICEConnectionInfo) HasCandidates() bool {
return len(i.Local) > 0 || len(i.Remote) > 0
}
// --------------------------------------------
type ICEConnectionDetails struct {
ICEConnectionInfo
lock sync.Mutex
logger logger.Logger
} }
func NewICEConnectionDetails(transport livekit.SignalTarget, l logger.Logger) *ICEConnectionDetails { func NewICEConnectionDetails(transport livekit.SignalTarget, l logger.Logger) *ICEConnectionDetails {
d := &ICEConnectionDetails{ d := &ICEConnectionDetails{
Transport: transport, ICEConnectionInfo: ICEConnectionInfo{
Type: ICEConnectionTypeUnknown, Transport: transport,
logger: l, Type: ICEConnectionTypeUnknown,
},
logger: l,
} }
return d return d
} }
func (d *ICEConnectionDetails) HasCandidates() bool { func (d *ICEConnectionDetails) GetInfo() *ICEConnectionInfo {
d.lock.Lock() d.lock.Lock()
defer d.lock.Unlock() defer d.lock.Unlock()
return len(d.Local) > 0 || len(d.Remote) > 0 info := &ICEConnectionInfo{
}
// Clone returns a copy of the ICEConnectionDetails, where fields can be read without locking
func (d *ICEConnectionDetails) Clone() *ICEConnectionDetails {
d.lock.Lock()
defer d.lock.Unlock()
clone := &ICEConnectionDetails{
Transport: d.Transport, Transport: d.Transport,
Type: d.Type, Type: d.Type,
logger: d.logger,
Local: make([]*ICECandidateExtended, 0, len(d.Local)), Local: make([]*ICECandidateExtended, 0, len(d.Local)),
Remote: make([]*ICECandidateExtended, 0, len(d.Remote)), Remote: make([]*ICECandidateExtended, 0, len(d.Remote)),
} }
for _, c := range d.Local { for _, c := range d.Local {
clone.Local = append(clone.Local, &ICECandidateExtended{ info.Local = append(info.Local, &ICECandidateExtended{
Local: c.Local, Local: c.Local,
Filtered: c.Filtered, Filtered: c.Filtered,
Selected: c.Selected, Selected: c.Selected,
@@ -91,14 +97,14 @@ func (d *ICEConnectionDetails) Clone() *ICEConnectionDetails {
}) })
} }
for _, c := range d.Remote { for _, c := range d.Remote {
clone.Remote = append(clone.Remote, &ICECandidateExtended{ info.Remote = append(info.Remote, &ICECandidateExtended{
Remote: c.Remote, Remote: c.Remote,
Filtered: c.Filtered, Filtered: c.Filtered,
Selected: c.Selected, Selected: c.Selected,
Trickle: c.Trickle, Trickle: c.Trickle,
}) })
} }
return clone return info
} }
func (d *ICEConnectionDetails) AddLocalCandidate(c *webrtc.ICECandidate, filtered, trickle bool) { func (d *ICEConnectionDetails) AddLocalCandidate(c *webrtc.ICECandidate, filtered, trickle bool) {
+1 -1
View File
@@ -321,7 +321,7 @@ type LocalParticipant interface {
GetBufferFactory() *buffer.Factory GetBufferFactory() *buffer.Factory
GetPlayoutDelayConfig() *livekit.PlayoutDelay GetPlayoutDelayConfig() *livekit.PlayoutDelay
GetPendingTrack(trackID livekit.TrackID) *livekit.TrackInfo GetPendingTrack(trackID livekit.TrackID) *livekit.TrackInfo
GetICEConnectionDetails() []*ICEConnectionDetails GetICEConnectionInfo() []*ICEConnectionInfo
HasConnected() bool HasConnected() bool
GetEnabledPublishCodecs() []*livekit.Codec GetEnabledPublishCodecs() []*livekit.Codec
@@ -306,15 +306,15 @@ type FakeLocalParticipant struct {
getICEConfigReturnsOnCall map[int]struct { getICEConfigReturnsOnCall map[int]struct {
result1 *livekit.ICEConfig result1 *livekit.ICEConfig
} }
GetICEConnectionDetailsStub func() []*types.ICEConnectionDetails GetICEConnectionInfoStub func() []*types.ICEConnectionInfo
getICEConnectionDetailsMutex sync.RWMutex getICEConnectionInfoMutex sync.RWMutex
getICEConnectionDetailsArgsForCall []struct { getICEConnectionInfoArgsForCall []struct {
} }
getICEConnectionDetailsReturns struct { getICEConnectionInfoReturns struct {
result1 []*types.ICEConnectionDetails result1 []*types.ICEConnectionInfo
} }
getICEConnectionDetailsReturnsOnCall map[int]struct { getICEConnectionInfoReturnsOnCall map[int]struct {
result1 []*types.ICEConnectionDetails result1 []*types.ICEConnectionInfo
} }
GetLoggerStub func() logger.Logger GetLoggerStub func() logger.Logger
getLoggerMutex sync.RWMutex getLoggerMutex sync.RWMutex
@@ -2568,15 +2568,15 @@ func (fake *FakeLocalParticipant) GetICEConfigReturnsOnCall(i int, result1 *live
}{result1} }{result1}
} }
func (fake *FakeLocalParticipant) GetICEConnectionDetails() []*types.ICEConnectionDetails { func (fake *FakeLocalParticipant) GetICEConnectionInfo() []*types.ICEConnectionInfo {
fake.getICEConnectionDetailsMutex.Lock() fake.getICEConnectionInfoMutex.Lock()
ret, specificReturn := fake.getICEConnectionDetailsReturnsOnCall[len(fake.getICEConnectionDetailsArgsForCall)] ret, specificReturn := fake.getICEConnectionInfoReturnsOnCall[len(fake.getICEConnectionInfoArgsForCall)]
fake.getICEConnectionDetailsArgsForCall = append(fake.getICEConnectionDetailsArgsForCall, struct { fake.getICEConnectionInfoArgsForCall = append(fake.getICEConnectionInfoArgsForCall, struct {
}{}) }{})
stub := fake.GetICEConnectionDetailsStub stub := fake.GetICEConnectionInfoStub
fakeReturns := fake.getICEConnectionDetailsReturns fakeReturns := fake.getICEConnectionInfoReturns
fake.recordInvocation("GetICEConnectionDetails", []interface{}{}) fake.recordInvocation("GetICEConnectionInfo", []interface{}{})
fake.getICEConnectionDetailsMutex.Unlock() fake.getICEConnectionInfoMutex.Unlock()
if stub != nil { if stub != nil {
return stub() return stub()
} }
@@ -2586,38 +2586,38 @@ func (fake *FakeLocalParticipant) GetICEConnectionDetails() []*types.ICEConnecti
return fakeReturns.result1 return fakeReturns.result1
} }
func (fake *FakeLocalParticipant) GetICEConnectionDetailsCallCount() int { func (fake *FakeLocalParticipant) GetICEConnectionInfoCallCount() int {
fake.getICEConnectionDetailsMutex.RLock() fake.getICEConnectionInfoMutex.RLock()
defer fake.getICEConnectionDetailsMutex.RUnlock() defer fake.getICEConnectionInfoMutex.RUnlock()
return len(fake.getICEConnectionDetailsArgsForCall) return len(fake.getICEConnectionInfoArgsForCall)
} }
func (fake *FakeLocalParticipant) GetICEConnectionDetailsCalls(stub func() []*types.ICEConnectionDetails) { func (fake *FakeLocalParticipant) GetICEConnectionInfoCalls(stub func() []*types.ICEConnectionInfo) {
fake.getICEConnectionDetailsMutex.Lock() fake.getICEConnectionInfoMutex.Lock()
defer fake.getICEConnectionDetailsMutex.Unlock() defer fake.getICEConnectionInfoMutex.Unlock()
fake.GetICEConnectionDetailsStub = stub fake.GetICEConnectionInfoStub = stub
} }
func (fake *FakeLocalParticipant) GetICEConnectionDetailsReturns(result1 []*types.ICEConnectionDetails) { func (fake *FakeLocalParticipant) GetICEConnectionInfoReturns(result1 []*types.ICEConnectionInfo) {
fake.getICEConnectionDetailsMutex.Lock() fake.getICEConnectionInfoMutex.Lock()
defer fake.getICEConnectionDetailsMutex.Unlock() defer fake.getICEConnectionInfoMutex.Unlock()
fake.GetICEConnectionDetailsStub = nil fake.GetICEConnectionInfoStub = nil
fake.getICEConnectionDetailsReturns = struct { fake.getICEConnectionInfoReturns = struct {
result1 []*types.ICEConnectionDetails result1 []*types.ICEConnectionInfo
}{result1} }{result1}
} }
func (fake *FakeLocalParticipant) GetICEConnectionDetailsReturnsOnCall(i int, result1 []*types.ICEConnectionDetails) { func (fake *FakeLocalParticipant) GetICEConnectionInfoReturnsOnCall(i int, result1 []*types.ICEConnectionInfo) {
fake.getICEConnectionDetailsMutex.Lock() fake.getICEConnectionInfoMutex.Lock()
defer fake.getICEConnectionDetailsMutex.Unlock() defer fake.getICEConnectionInfoMutex.Unlock()
fake.GetICEConnectionDetailsStub = nil fake.GetICEConnectionInfoStub = nil
if fake.getICEConnectionDetailsReturnsOnCall == nil { if fake.getICEConnectionInfoReturnsOnCall == nil {
fake.getICEConnectionDetailsReturnsOnCall = make(map[int]struct { fake.getICEConnectionInfoReturnsOnCall = make(map[int]struct {
result1 []*types.ICEConnectionDetails result1 []*types.ICEConnectionInfo
}) })
} }
fake.getICEConnectionDetailsReturnsOnCall[i] = struct { fake.getICEConnectionInfoReturnsOnCall[i] = struct {
result1 []*types.ICEConnectionDetails result1 []*types.ICEConnectionInfo
}{result1} }{result1}
} }
@@ -6969,8 +6969,8 @@ func (fake *FakeLocalParticipant) Invocations() map[string][][]interface{} {
defer fake.getEnabledPublishCodecsMutex.RUnlock() defer fake.getEnabledPublishCodecsMutex.RUnlock()
fake.getICEConfigMutex.RLock() fake.getICEConfigMutex.RLock()
defer fake.getICEConfigMutex.RUnlock() defer fake.getICEConfigMutex.RUnlock()
fake.getICEConnectionDetailsMutex.RLock() fake.getICEConnectionInfoMutex.RLock()
defer fake.getICEConnectionDetailsMutex.RUnlock() defer fake.getICEConnectionInfoMutex.RUnlock()
fake.getLoggerMutex.RLock() fake.getLoggerMutex.RLock()
defer fake.getLoggerMutex.RUnlock() defer fake.getLoggerMutex.RUnlock()
fake.getPacerMutex.RLock() fake.getPacerMutex.RLock()
+3 -1
View File
@@ -196,7 +196,9 @@ type refInfo struct {
} }
func (r refInfo) MarshalLogObject(e zapcore.ObjectEncoder) error { func (r refInfo) MarshalLogObject(e zapcore.ObjectEncoder) error {
e.AddObject("senderReport", buffer.WrappedRTCPSenderReportStateLogger{r.senderReport}) e.AddObject("senderReport", buffer.WrappedRTCPSenderReportStateLogger{
RTCPSenderReportState: r.senderReport,
})
e.AddUint64("tsOffset", r.tsOffset) e.AddUint64("tsOffset", r.tsOffset)
e.AddBool("isTSOffsetValid", r.isTSOffsetValid) e.AddBool("isTSOffsetValid", r.isTSOffsetValid)
return nil return nil