From d02ae062e441128eba0f15724bf7ce0fe2bb9337 Mon Sep 17 00:00:00 2001 From: Siyuan Date: Fri, 10 Oct 2025 22:44:57 +0000 Subject: [PATCH] fix: make timesync non-blocking --- network.go | 8 +++++--- pkg/nmlite/interface_state.go | 4 ++-- pkg/nmlite/utils.go | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/network.go b/network.go index b957df8c..bafd8bb1 100644 --- a/network.go +++ b/network.go @@ -91,9 +91,11 @@ func triggerTimeSyncOnNetworkStateChange() { } // sync time - if err := timeSync.Sync(); err != nil { - networkLogger.Error().Err(err).Msg("failed to sync time after network state change") - } + go func() { + if err := timeSync.Sync(); err != nil { + networkLogger.Error().Err(err).Msg("failed to sync time after network state change") + } + }() } func networkStateChanged(_ string, state types.InterfaceState) { diff --git a/pkg/nmlite/interface_state.go b/pkg/nmlite/interface_state.go index 8a60784b..087cf010 100644 --- a/pkg/nmlite/interface_state.go +++ b/pkg/nmlite/interface_state.go @@ -120,12 +120,12 @@ func (im *InterfaceManager) updateInterfaceStateAddresses(nl *link.Link) (bool, } } - if !compareStringSlices(im.state.IPv4Addresses, ipv4Addresses) { + if !sortAndCompareStringSlices(im.state.IPv4Addresses, ipv4Addresses) { im.state.IPv4Addresses = ipv4Addresses stateChanged = true } - if !compareIPv6AddressSlices(im.state.IPv6Addresses, ipv6Addresses) { + if !sortAndCompareIPv6AddressSlices(im.state.IPv6Addresses, ipv6Addresses) { im.state.IPv6Addresses = ipv6Addresses stateChanged = true } diff --git a/pkg/nmlite/utils.go b/pkg/nmlite/utils.go index 5a6eb0b8..49ed0078 100644 --- a/pkg/nmlite/utils.go +++ b/pkg/nmlite/utils.go @@ -25,7 +25,7 @@ func lifetimeToTime(lifetime int) *time.Time { return &t } -func compareStringSlices(a, b []string) bool { +func sortAndCompareStringSlices(a, b []string) bool { if len(a) != len(b) { return false } @@ -42,7 +42,7 @@ func compareStringSlices(a, b []string) bool { return true } -func compareIPv6AddressSlices(a, b []types.IPv6Address) bool { +func sortAndCompareIPv6AddressSlices(a, b []types.IPv6Address) bool { if len(a) != len(b) { return false }