mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 08:16:39 +00:00
[client] Fix shutdown blocking on stuck ICE agent close (#4780)
This commit is contained in:
@@ -22,6 +22,8 @@ const (
|
|||||||
iceFailedTimeoutDefault = 6 * time.Second
|
iceFailedTimeoutDefault = 6 * time.Second
|
||||||
// iceRelayAcceptanceMinWaitDefault is the same as in the Pion ICE package
|
// iceRelayAcceptanceMinWaitDefault is the same as in the Pion ICE package
|
||||||
iceRelayAcceptanceMinWaitDefault = 2 * time.Second
|
iceRelayAcceptanceMinWaitDefault = 2 * time.Second
|
||||||
|
// iceAgentCloseTimeout is the maximum time to wait for ICE agent close to complete
|
||||||
|
iceAgentCloseTimeout = 3 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
type ThreadSafeAgent struct {
|
type ThreadSafeAgent struct {
|
||||||
@@ -32,7 +34,17 @@ type ThreadSafeAgent struct {
|
|||||||
func (a *ThreadSafeAgent) Close() error {
|
func (a *ThreadSafeAgent) Close() error {
|
||||||
var err error
|
var err error
|
||||||
a.once.Do(func() {
|
a.once.Do(func() {
|
||||||
err = a.Agent.Close()
|
done := make(chan error, 1)
|
||||||
|
go func() {
|
||||||
|
done <- a.Agent.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
select {
|
||||||
|
case err = <-done:
|
||||||
|
case <-time.After(iceAgentCloseTimeout):
|
||||||
|
log.Warnf("ICE agent close timed out after %v, proceeding with cleanup", iceAgentCloseTimeout)
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user