From 6a7c4036d373ad662d7738e1a2380d434e2b7daa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Tue, 12 Nov 2024 10:43:04 +0800 Subject: [PATCH] Fix monitor --- go.mod | 2 +- go.sum | 4 ++-- monitor_darwin.go | 9 ++++----- monitor_shared.go | 7 ++++++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index a4323c1..fc08033 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/sagernet/gvisor v0.0.0-20241021032506-a4324256e4a3 github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a github.com/sagernet/nftables v0.3.0-beta.4 - github.com/sagernet/sing v0.6.0-alpha.4 + github.com/sagernet/sing v0.6.0-alpha.5 go4.org/netipx v0.0.0-20231129151722-fdeea329fbba golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 golang.org/x/net v0.26.0 diff --git a/go.sum b/go.sum index 9696f5e..e21f79e 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a h1:ObwtHN2VpqE0ZN github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM= github.com/sagernet/nftables v0.3.0-beta.4 h1:kbULlAwAC3jvdGAC1P5Fa3GSxVwQJibNenDW2zaXr8I= github.com/sagernet/nftables v0.3.0-beta.4/go.mod h1:OQXAjvjNGGFxaTgVCSTRIhYB5/llyVDeapVoENYBDS8= -github.com/sagernet/sing v0.6.0-alpha.4 h1:h9oshzhaY0ESPC9HERcXtT9MhK7Oyo/IWXVu1uIiw3Y= -github.com/sagernet/sing v0.6.0-alpha.4/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak= +github.com/sagernet/sing v0.6.0-alpha.5 h1:AQHBy2It7mSefP9eaic03yymaxPA2IPsPIClLT+IM0I= +github.com/sagernet/sing v0.6.0-alpha.5/go.mod h1:ARkL0gM13/Iv5VCZmci/NuoOlePoIsW0m7BWfln/Hak= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8= github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM= diff --git a/monitor_darwin.go b/monitor_darwin.go index 65e9330..3bf6ac8 100644 --- a/monitor_darwin.go +++ b/monitor_darwin.go @@ -107,11 +107,10 @@ func (m *networkUpdateMonitor) Close() error { } func (m *defaultInterfaceMonitor) checkUpdate() error { - err := m.interfaceFinder.Update() - if err != nil { - return E.Cause(err, "update interfaces") - } - var defaultInterface *control.Interface + var ( + defaultInterface *control.Interface + err error + ) if m.underNetworkExtension { defaultInterface, err = m.getDefaultInterfaceBySocket() if err != nil { diff --git a/monitor_shared.go b/monitor_shared.go index f4d0e97..d742906 100644 --- a/monitor_shared.go +++ b/monitor_shared.go @@ -74,7 +74,12 @@ func (m *defaultInterfaceMonitor) delayCheckUpdate() { } func (m *defaultInterfaceMonitor) postCheckUpdate() { - err := m.checkUpdate() + err := m.interfaceFinder.Update() + if err != nil { + m.logger.Error("update interface: ", err) + return + } + err = m.checkUpdate() if errors.Is(err, ErrNoRoute) { if !m.noRoute { m.noRoute = true