Skip to content

Commit

Permalink
special-case datamanager sync.isOffline on windows (#4735)
Browse files Browse the repository at this point in the history
  • Loading branch information
abe-winter authored Jan 22, 2025
1 parent 36db2d2 commit 1c4d115
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions services/datamanager/builtin/sync/connectivity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sync

import (
"net"
"runtime"
"time"

"go.viam.com/utils/rpc"
Expand Down Expand Up @@ -35,9 +36,25 @@ func (oc offlineChecker) GetState() connectivity.State {
return connectivity.Ready
}

// returns true if the device is offline.
func isOffline() bool {
timeout := 5 * time.Second
_, err := net.DialTimeout("tcp", "app.viam.com:443", timeout)
// If there's an error, the system is likely offline.
return err != nil
attempts := 1
if runtime.GOOS == "windows" {
// TODO(RSDK-8344): this is temporary as we 1) debug connectivity issues on windows,
// and 2) migrate to using the native checks on the underlying connection.
timeout = 15 * time.Second
attempts = 2
}
for i := range attempts {
conn, err := net.DialTimeout("tcp", "app.viam.com:443", timeout)
if err == nil {
conn.Close() //nolint:gosec,errcheck
return false
}
if i < attempts-1 {
time.Sleep(time.Second)
}
}
return true
}

0 comments on commit 1c4d115

Please sign in to comment.