Add close monitor

This commit is contained in:
世界 2023-04-08 08:10:03 +08:00
parent e1e217854e
commit 62425ad3e4
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -10,6 +10,7 @@ import (
"sort"
"strings"
"syscall"
"time"
"github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/common/badjsonmerge"
@ -177,7 +178,10 @@ func run() error {
}
}
cancel()
closeCtx, closed := context.WithCancel(context.Background())
go closeMonitor(closeCtx)
instance.Close()
closed()
if osSignal != syscall.SIGHUP {
return nil
}
@ -185,3 +189,13 @@ func run() error {
}
}
}
func closeMonitor(ctx context.Context) {
time.Sleep(3 * time.Second)
select {
case <-ctx.Done():
return
default:
}
log.Fatal("sing-box did not close!")
}