diff --git a/agent.go b/agent.go index 82de746d..f80c62e3 100644 --- a/agent.go +++ b/agent.go @@ -706,7 +706,12 @@ func (a *Agent) checkKeepalive() { // AddRemoteCandidate adds a new remote candidate func (a *Agent) AddRemoteCandidate(c Candidate) error { - // canot check for network yet because it might not be applied + // accept nil candidate. aka end-of-candidates will not fail + if c == nil { + return nil + } + + // cannot check for network yet because it might not be applied // when mDNS hostame is used. if c.TCPType() == TCPTypeActive { // TCP Candidates with tcptype active will probe server passive ones, so diff --git a/agent_test.go b/agent_test.go index 05361f34..990ae3ef 100644 --- a/agent_test.go +++ b/agent_test.go @@ -1686,3 +1686,16 @@ func TestLiteLifecycle(t *testing.T) { <-bFailed assert.NoError(t, bAgent.Close()) } + +func TestNilCandidate(t *testing.T) { + var config AgentConfig + a, err := NewAgent(&config) + if err != nil { + t.Fatalf("Error constructing ice.Agent: %v", err) + } + + err = a.AddRemoteCandidate(nil) + assert.NoError(t, err) + + assert.NoError(t, a.Close()) +} diff --git a/debug.test b/debug.test new file mode 100644 index 00000000..99dab34c Binary files /dev/null and b/debug.test differ