From c60a944aacad8ce0a5c2a43213eae58b33ce0ed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 23 Sep 2023 12:41:51 +0800 Subject: [PATCH] Fix missing context in geo resources download --- cmd/sing-box/cmd_run.go | 4 +++- route/router_geo_resources.go | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/sing-box/cmd_run.go b/cmd/sing-box/cmd_run.go index 62df6092..46f3495f 100644 --- a/cmd/sing-box/cmd_run.go +++ b/cmd/sing-box/cmd_run.go @@ -143,14 +143,16 @@ func create() (*box.Box, context.CancelFunc, error) { signal.Stop(osSignals) close(osSignals) }() - + startCtx, finishStart := context.WithCancel(context.Background()) go func() { _, loaded := <-osSignals if loaded { cancel() + closeMonitor(startCtx) } }() err = instance.Start() + finishStart() if err != nil { cancel() return nil, nil, E.Cause(err, "start service") diff --git a/route/router_geo_resources.go b/route/router_geo_resources.go index d4b8d8b6..7abc5db5 100644 --- a/route/router_geo_resources.go +++ b/route/router_geo_resources.go @@ -173,7 +173,11 @@ func (r *Router) downloadGeoIPDatabase(savePath string) error { }, } defer httpClient.CloseIdleConnections() - response, err := httpClient.Get(downloadURL) + request, err := http.NewRequest("GET", downloadURL, nil) + if err != nil { + return err + } + response, err := httpClient.Do(request.WithContext(r.ctx)) if err != nil { return err } @@ -221,7 +225,11 @@ func (r *Router) downloadGeositeDatabase(savePath string) error { }, } defer httpClient.CloseIdleConnections() - response, err := httpClient.Get(downloadURL) + request, err := http.NewRequest("GET", downloadURL, nil) + if err != nil { + return err + } + response, err := httpClient.Do(request.WithContext(r.ctx)) if err != nil { return err }