From ad4f7c09e10058ae6408699ea083a72956616b07 Mon Sep 17 00:00:00 2001 From: Siyuan Date: Thu, 20 Nov 2025 20:41:37 +0000 Subject: [PATCH] Revert "fix(network): only trigger time sync when network transitions to online rather than every state change" This reverts commit 86be6df1d376651e48a2f4a2807dcbd4fdca9225. --- cmd/main.go | 7 +++++-- network.go | 10 +--------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 2fd27dae..fcf2cdfe 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -101,6 +101,11 @@ func supervise() error { cmd.Args = os.Args logFile, err := os.CreateTemp("", "jetkvm-stdout.log") + defer func() { + // we don't care about the errors here + _ = logFile.Close() + _ = os.Remove(logFile.Name()) + }() if err != nil { return fmt.Errorf("failed to create log file: %w", err) } @@ -128,8 +133,6 @@ func supervise() error { } if exiterr, ok := cmdErr.(*exec.ExitError); ok { - // createErrorDump will close and rename the file if successful - // Note: os.Exit bypasses defer, but file is already handled by createErrorDump createErrorDump(logFile) os.Exit(exiterr.ExitCode()) } diff --git a/network.go b/network.go index b2b224f0..eb14c70d 100644 --- a/network.go +++ b/network.go @@ -6,7 +6,6 @@ import ( "net" "net/http" "reflect" - "sync/atomic" "time" "github.com/jetkvm/kvm/internal/confparser" @@ -119,10 +118,6 @@ func setPublicIPReadyState(ipv4Ready, ipv6Ready bool) { publicIPState.SetIPv4AndIPv6(ipv4Ready, ipv6Ready) } -var ( - isOnline = &atomic.Bool{} -) - func networkStateChanged(_ string, state types.InterfaceState) { // do not block the main thread go waitCtrlAndRequestDisplayUpdate(true, "network_state_changed") @@ -131,10 +126,7 @@ func networkStateChanged(_ string, state types.InterfaceState) { writeJSONRPCEvent("networkState", state.ToRpcInterfaceState(), currentSession) } - previousOnline := isOnline.Load() - isOnline.Store(state.Online) - - if state.Online && !previousOnline { + if state.Online { networkLogger.Info().Msg("network state changed to online, triggering time sync") triggerTimeSyncOnNetworkStateChange() }