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 }