mirror of
https://github.com/SagerNet/sing-box.git
synced 2026-06-03 21:01:12 +08:00
fix(libbox): prevent goroutine leak in ExchangeContext.OnCancel
The OnCancel goroutine blocked indefinitely on c.context.Done(). If the context was never cancelled, the goroutine leaked. Add a timeout via time.After with DNSTimeout to ensure termination. Fixes #4162
This commit is contained in:
parent
812a8fdaee
commit
320a3f6f43
@ -5,6 +5,7 @@ import (
|
||||
"net/netip"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
@ -121,8 +122,11 @@ type ExchangeContext struct {
|
||||
|
||||
func (c *ExchangeContext) OnCancel(callback Func) {
|
||||
go func() {
|
||||
<-c.context.Done()
|
||||
callback.Invoke()
|
||||
select {
|
||||
case <-c.context.Done():
|
||||
callback.Invoke()
|
||||
case <-time.After(C.DNSTimeout):
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user