Fix: provider filter potential panic

This commit is contained in:
Dreamacro 2021-11-21 17:44:03 +08:00
parent 1401a82bb0
commit b1bed7623d
2 changed files with 7 additions and 3 deletions

View file

@ -60,5 +60,5 @@ func ParseProxyProvider(name string, mapping map[string]interface{}) (types.Prox
interval := time.Duration(uint(schema.Interval)) * time.Second interval := time.Duration(uint(schema.Interval)) * time.Second
filter := schema.Filter filter := schema.Filter
return NewProxySetProvider(name, interval, filter, vehicle, hc), nil return NewProxySetProvider(name, interval, filter, vehicle, hc)
} }

View file

@ -96,7 +96,11 @@ func stopProxyProvider(pd *ProxySetProvider) {
pd.fetcher.Destroy() pd.fetcher.Destroy()
} }
func NewProxySetProvider(name string, interval time.Duration, filter string, vehicle types.Vehicle, hc *HealthCheck) *ProxySetProvider { func NewProxySetProvider(name string, interval time.Duration, filter string, vehicle types.Vehicle, hc *HealthCheck) (*ProxySetProvider, error) {
if _, err := regexp.Compile(filter); err != nil {
return nil, fmt.Errorf("invalid filter regex: %w", err)
}
if hc.auto() { if hc.auto() {
go hc.process() go hc.process()
} }
@ -150,7 +154,7 @@ func NewProxySetProvider(name string, interval time.Duration, filter string, veh
wrapper := &ProxySetProvider{pd} wrapper := &ProxySetProvider{pd}
runtime.SetFinalizer(wrapper, stopProxyProvider) runtime.SetFinalizer(wrapper, stopProxyProvider)
return wrapper return wrapper, nil
} }
// for auto gc // for auto gc