From 858d089a8acfb8486008c0cc78e65fb740716170 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 --- monitor_darwin.go | 9 ++++----- monitor_shared.go | 7 ++++++- 2 files changed, 10 insertions(+), 6 deletions(-) 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