diff --git a/adapter/provider/provider.go b/adapter/provider/provider.go index 96852c4b..4138c0de 100644 --- a/adapter/provider/provider.go +++ b/adapter/provider/provider.go @@ -17,6 +17,7 @@ import ( C "github.com/Dreamacro/clash/constant" types "github.com/Dreamacro/clash/constant/provider" "github.com/Dreamacro/clash/log" + "github.com/Dreamacro/clash/tunnel/statistic" "github.com/dlclark/regexp2" "gopkg.in/yaml.v3" @@ -81,6 +82,7 @@ func (pp *proxySetProvider) Initial() error { } pp.OnUpdate(elm) pp.getSubscriptionInfo() + pp.closeAllConnections() return nil } @@ -138,6 +140,18 @@ func (pp *proxySetProvider) getSubscriptionInfo() { }() } +func (pp *proxySetProvider) closeAllConnections() { + snapshot := statistic.DefaultManager.Snapshot() + for _, c := range snapshot.Connections { + for _, chain := range c.Chains() { + if chain == pp.Name() { + _ = c.Close() + break + } + } + } +} + func stopProxyProvider(pd *ProxySetProvider) { pd.healthCheck.close() _ = pd.Fetcher.Destroy() diff --git a/tunnel/statistic/tracker.go b/tunnel/statistic/tracker.go index 3678a19d..96376eb4 100644 --- a/tunnel/statistic/tracker.go +++ b/tunnel/statistic/tracker.go @@ -15,6 +15,7 @@ import ( type tracker interface { ID() string Close() error + C.Connection } type trackerInfo struct {