Fix missing context in geo resources download

This commit is contained in:
世界 2023-09-23 12:41:51 +08:00
parent 17584c245f
commit c60a944aac
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 13 additions and 3 deletions

View file

@ -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")

View file

@ -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
}