chore: close all connections after proxySet initial

This commit is contained in:
wwqgtxx 2023-04-12 18:50:51 +08:00
parent 5d7fd47cf9
commit aaf534427e
2 changed files with 15 additions and 0 deletions

View file

@ -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()

View file

@ -15,6 +15,7 @@ import (
type tracker interface {
ID() string
Close() error
C.Connection
}
type trackerInfo struct {