Skip to content

Commit

Permalink
reuse connectivity check ticker
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwe committed Apr 13, 2024
1 parent 0860817 commit fb3060c
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,35 +372,36 @@ func (a *Agent) connectivityChecks() {
}
}

for {
interval := defaultKeepaliveInterval
interval := defaultKeepaliveInterval

Check warning on line 375 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L375

Added line #L375 was not covered by tests

updateInterval := func(x time.Duration) {
if x != 0 && (interval == 0 || interval > x) {
interval = x
}
updateInterval := func(x time.Duration) {
if x != 0 && (interval == 0 || interval > x) {
interval = x

Check warning on line 379 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L377-L379

Added lines #L377 - L379 were not covered by tests
}
}

switch lastConnectionState {
case ConnectionStateNew, ConnectionStateChecking: // While connecting, check candidates more frequently
updateInterval(a.checkInterval)
case ConnectionStateConnected, ConnectionStateDisconnected:
updateInterval(a.keepaliveInterval)
default:
}
// Ensure we run our task loop as quickly as the minimum of our various configured timeouts
updateInterval(a.disconnectedTimeout)
updateInterval(a.failedTimeout)
switch lastConnectionState {
case ConnectionStateNew, ConnectionStateChecking: // While connecting, check candidates more frequently
updateInterval(a.checkInterval)
case ConnectionStateConnected, ConnectionStateDisconnected:
updateInterval(a.keepaliveInterval)
default:

Check warning on line 388 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L383-L388

Added lines #L383 - L388 were not covered by tests
}
// Ensure we run our task loop as quickly as the minimum of our various configured timeouts
updateInterval(a.disconnectedTimeout)
updateInterval(a.failedTimeout)

Check warning on line 392 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L391-L392

Added lines #L391 - L392 were not covered by tests

t := time.NewTimer(interval)
t := time.NewTicker(interval)
defer t.Stop()

Check warning on line 395 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L394-L395

Added lines #L394 - L395 were not covered by tests

for {

Check warning on line 397 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L397

Added line #L397 was not covered by tests
select {
case <-a.forceCandidateContact:
t.Stop()
t.Reset(interval)

Check warning on line 400 in agent.go

View check run for this annotation

Codecov / codecov/patch

agent.go#L400

Added line #L400 was not covered by tests
contact()
case <-t.C:
contact()
case <-a.loop.Done():
t.Stop()
return
}
}
Expand Down

0 comments on commit fb3060c

Please sign in to comment.