finish gather before close

This commit is contained in:
boks1971
2025-12-03 16:19:46 +05:30
parent 4a082cb51c
commit 2e9a3289a8

View File

@@ -401,6 +401,11 @@ func newAgentWithConfig(agent *Agent, opts ...AgentOption) (*Agent, error) {
}
agent.loop = taskloop.New(func() {
agent.gatherCandidateCancel()
if agent.gatherCandidateDone != nil {
<-agent.gatherCandidateDone
}
agent.removeUfragFromMux()
agent.deleteAllCandidates()
agent.startedFn()
@@ -411,11 +416,6 @@ func newAgentWithConfig(agent *Agent, opts ...AgentOption) (*Agent, error) {
agent.closeMulticastConn()
agent.updateConnectionState(ConnectionStateClosed)
agent.gatherCandidateCancel()
if agent.gatherCandidateDone != nil {
<-agent.gatherCandidateDone
}
})
// Restart is also used to initialize the agent for the first time