diff --git a/core/src/main/golang/native/main.go b/core/src/main/golang/native/main.go index 9293339898d2a06fe33fa00a450753b86e2fdfcd..01c68b20da80af338d93195342c4f2704fb36238 100644 --- a/core/src/main/golang/native/main.go +++ b/core/src/main/golang/native/main.go @@ -36,6 +36,7 @@ func coreInit(home, versionName C.c_string, sdkVersion C.int) { func reset() { config.LoadDefault() tunnel.ResetStatistic() + tunnel.CloseAllConnections() runtime.GC() } diff --git a/core/src/main/golang/native/tunnel/conn.go b/core/src/main/golang/native/tunnel/conn.go index c0b05bb3728d2c6c71f3f9edcf8bb79f7d8f0e76..beb7c3c91dcdca6d4b73506471fafb932bd8f188 100644 --- a/core/src/main/golang/native/tunnel/conn.go +++ b/core/src/main/golang/native/tunnel/conn.go @@ -5,6 +5,12 @@ import ( "github.com/Dreamacro/clash/tunnel/statistic" ) +func CloseAllConnections() { + for _, c := range statistic.DefaultManager.Snapshot().Connections { + _ = c.Close() + } +} + func closeMatch(filter func(conn C.Conn) bool) { for _, c := range statistic.DefaultManager.Snapshot().Connections { if cc, ok := c.(C.Conn); ok {