From 62425ad3e4806d361fce24957423a702e52e4fa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 8 Apr 2023 08:10:03 +0800 Subject: [PATCH] Add close monitor --- cmd/sing-box/cmd_run.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/sing-box/cmd_run.go b/cmd/sing-box/cmd_run.go index 9e296aa6..62df6092 100644 --- a/cmd/sing-box/cmd_run.go +++ b/cmd/sing-box/cmd_run.go @@ -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!") +}