Skip to content

Commit

Permalink
fix: proxy config reload panic
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Nov 13, 2024
1 parent 2523282 commit 1a96ec9
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()

Check warning on line 227 in pkg/base/model.go

View check run for this annotation

Codecov / codecov/patch

pkg/base/model.go#L227

Added line #L227 was not covered by tests
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()

Check warning on line 242 in pkg/base/model.go

View check run for this annotation

Codecov / codecov/patch

pkg/base/model.go#L242

Added line #L242 was not covered by tests
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()

Check warning on line 274 in pkg/base/model.go

View check run for this annotation

Codecov / codecov/patch

pkg/base/model.go#L270-L274

Added lines #L270 - L274 were not covered by tests
}

func parseUrlSafe(rawUrl string) *url.URL {
u, err := url.Parse(rawUrl)
if err != nil {
Expand Down

0 comments on commit 1a96ec9

Please sign in to comment.