mirror of
https://github.com/netbirdio/ice-old.git
synced 2026-05-22 17:08:24 -07:00
Fix close delay collecting STUN candidates
This was causing a 5s delay when closing the agent.
This commit is contained in:
committed by
Sean DuBois
parent
e6cfc5103e
commit
1bbdb40185
@@ -402,7 +402,7 @@ func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, ne
|
||||
}
|
||||
}
|
||||
|
||||
func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkTypes []NetworkType) {
|
||||
func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkTypes []NetworkType) { //nolint:gocognit
|
||||
var wg sync.WaitGroup
|
||||
defer wg.Wait()
|
||||
|
||||
@@ -428,6 +428,18 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT
|
||||
closeConnAndLog(conn, a.log, fmt.Sprintf("Failed to listen for %s: %v\n", serverAddr.String(), err))
|
||||
return
|
||||
}
|
||||
// If the agent closes midway through the connection
|
||||
// we end it early to prevent close delay.
|
||||
cancelCtx, cancelFunc := context.WithCancel(ctx)
|
||||
defer cancelFunc()
|
||||
go func() {
|
||||
select {
|
||||
case <-cancelCtx.Done():
|
||||
return
|
||||
case <-a.done:
|
||||
_ = conn.Close()
|
||||
}
|
||||
}()
|
||||
|
||||
xoraddr, err := getXORMappedAddr(conn, serverAddr, stunGatherTimeout)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user