[client] Fix shutdown blocking on stuck ICE agent close (#4780)

This commit is contained in:
Viktor Liu
2025-11-13 13:24:51 +01:00
committed by GitHub
parent 6fb568728f
commit 27957036c9

View File

@@ -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
} }