Fix duplicate TCP candidates

Duplicate TCP candidates share the same candidateConn,
which would be closed if started before checking.
This commit is contained in:
hn8
2021-07-23 10:53:16 -04:00
committed by Sean DuBois
parent 04b16d58bd
commit 161b670ac4
2 changed files with 4 additions and 3 deletions
+3 -2
View File
@@ -808,11 +808,10 @@ func (a *Agent) addRemoteCandidate(c Candidate) {
func (a *Agent) addCandidate(ctx context.Context, c Candidate, candidateConn net.PacketConn) error {
return a.run(ctx, func(ctx context.Context, agent *Agent) {
c.start(a, candidateConn, a.startedCh)
set := a.localCandidates[c.NetworkType()]
for _, candidate := range set {
if candidate.Equal(c) {
a.log.Debugf("Ignore duplicate candidate: %s", c.String())
if err := c.close(); err != nil {
a.log.Warnf("Failed to close duplicate candidate: %v", err)
}
@@ -820,6 +819,8 @@ func (a *Agent) addCandidate(ctx context.Context, c Candidate, candidateConn net
}
}
c.start(a, candidateConn, a.startedCh)
set = append(set, c)
a.localCandidates[c.NetworkType()] = set
+1 -1
View File
@@ -159,7 +159,7 @@ func (m *TCPMuxDefault) handleConn(conn net.Conn) {
n, err := readStreamingPacket(conn, buf)
if err != nil {
m.params.Logger.Warnf("Error reading first packet: %s", err)
m.params.Logger.Warnf("Error reading first packet from %s: %s", conn.RemoteAddr().String(), err)
return
}