Skip to content

Commit 2795703

Browse files
authored
[client] Fix shutdown blocking on stuck ICE agent close (#4780)
1 parent 6fb5687 commit 2795703

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

client/internal/peer/ice/agent.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const (
2222
iceFailedTimeoutDefault = 6 * time.Second
2323
// iceRelayAcceptanceMinWaitDefault is the same as in the Pion ICE package
2424
iceRelayAcceptanceMinWaitDefault = 2 * time.Second
25+
// iceAgentCloseTimeout is the maximum time to wait for ICE agent close to complete
26+
iceAgentCloseTimeout = 3 * time.Second
2527
)
2628

2729
type ThreadSafeAgent struct {
@@ -32,7 +34,17 @@ type ThreadSafeAgent struct {
3234
func (a *ThreadSafeAgent) Close() error {
3335
var err error
3436
a.once.Do(func() {
35-
err = a.Agent.Close()
37+
done := make(chan error, 1)
38+
go func() {
39+
done <- a.Agent.Close()
40+
}()
41+
42+
select {
43+
case err = <-done:
44+
case <-time.After(iceAgentCloseTimeout):
45+
log.Warnf("ICE agent close timed out after %v, proceeding with cleanup", iceAgentCloseTimeout)
46+
err = nil
47+
}
3648
})
3749
return err
3850
}

0 commit comments

Comments
 (0)