Skip to content

Commit

Permalink
fix: proxy config reload panic (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie authored Nov 13, 2024
1 parent 2523282 commit aaf73de
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/base/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"golang.org/x/exp/slices"
"net/http"
"net/url"
"sync"
"time"
)

Expand Down Expand Up @@ -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 == "" {
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit aaf73de

Please sign in to comment.