fix: proxy config reload panic (#808)

This commit is contained in:
Levi authored and GitHub committed 2024-11-14 00:36:21 +08:00
1 parent 2523282a89
commit aaf73dec24
1 file changed
+12 -2
+12 -2
View File
@@ -7,6 +7,7 @@ import (
"golang.org/x/exp/slices"
"net/http"
"net/url"
"sync"
"time"
)
@@ -223,7 +224,7 @@ func (cfg *DownloaderProxyConfig) ToHandler() func(r *http.Request) (*url.URL, e
return nil
}
if cfg.System {
ieproxy.ReloadConf()
safeProxyReloadConf()
return ieproxy.GetProxyFunc()
}
if cfg.Scheme == "" || cfg.Host == "" {
@@ -238,7 +239,7 @@ func (cfg *DownloaderProxyConfig) ToUrl() *url.URL {
return nil
}
if cfg.System {
ieproxy.ReloadConf()
safeProxyReloadConf()
static := ieproxy.GetConf().Static
if static.Active && len(static.Protocols) > 0 {
// If only one protocol, use it
@@ -264,6 +265,15 @@ func (cfg *DownloaderProxyConfig) ToUrl() *url.URL {
return util.BuildProxyUrl(cfg.Scheme, cfg.Host, cfg.Usr, cfg.Pwd)
}
var prcLock sync.Mutex
func safeProxyReloadConf() {
prcLock.Lock()
defer prcLock.Unlock()
ieproxy.ReloadConf()
}
func parseUrlSafe(rawUrl string) *url.URL {
u, err := url.Parse(rawUrl)
if err != nil {