Skip to content

Commit

Permalink
Fix bug with mismatched visibility timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Otterverse committed Dec 18, 2024
1 parent 86fd474 commit b059dfd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions subsystems/provisioning/networkmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func (w *Provisioning) warnIfMultiplePrimaryNetworks() {
func (w *Provisioning) getVisibleNetworks() []NetworkInfo {
var visible []NetworkInfo
for _, nw := range w.netState.Networks() {
// note this does NOT use VisibleNetworkTimeout (like getCandidates does)
recentlySeen := nw.lastSeen.After(w.connState.getProvisioningChange().Add(time.Duration(w.Config().OfflineTimeout * -2)))

if !nw.isHotspot && recentlySeen {
Expand Down Expand Up @@ -511,8 +512,8 @@ func (w *Provisioning) getCandidates(ifName string) []string {
if nw.netType != NetworkTypeWifi || (nw.interfaceName != "" && nw.interfaceName != ifName) {
continue
}
// ssid seen within the past two minutes
visible := nw.lastSeen.After(time.Now().Add(time.Minute * -2))
// ssid seen within the past minute
visible := nw.lastSeen.After(time.Now().Add(VisibleNetworkTimeout * -1))

// ssid has a connection known to network manager
configured := nw.conn != nil
Expand Down
9 changes: 7 additions & 2 deletions subsystems/provisioning/scanning.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import (
errw "github.com/pkg/errors"
)

var ErrScanTimeout = errw.New("wifi scanning timed out")
var (
ErrScanTimeout = errw.New("wifi scanning timed out")

// how long is a scanned network "visible" for candidate selection?
VisibleNetworkTimeout = time.Minute
)

func (w *Provisioning) networkScan(ctx context.Context) error {
if w.connState.getProvisioning() && w.netState.NoScanInHotspot() {
Expand Down Expand Up @@ -124,7 +129,7 @@ func (w *Provisioning) networkScan(ctx context.Context) error {
}
nw.mu.Lock()
// if a network isn't visible, reset the times so we'll retry if it comes back
if nw.lastSeen.Before(time.Now().Add(time.Minute * -1)) {
if nw.lastSeen.Before(time.Now().Add(VisibleNetworkTimeout * -1)) {
nw.firstSeen = time.Time{}
nw.lastTried = time.Time{}
}
Expand Down

0 comments on commit b059dfd

Please sign in to comment.