sendPings sends websocket pings. We use a custom heartbeat routine here instead of `httpapi.Heartbeat` because we want to log the agent's last ping time.
(ctx context.Context)
| 311 | // We use a custom heartbeat routine here instead of `httpapi.Heartbeat` |
| 312 | // because we want to log the agent's last ping time. |
| 313 | func (m *agentConnectionMonitor) sendPings(ctx context.Context) { |
| 314 | t := time.NewTicker(m.pingPeriod) |
| 315 | defer t.Stop() |
| 316 | |
| 317 | for { |
| 318 | select { |
| 319 | case <-t.C: |
| 320 | case <-ctx.Done(): |
| 321 | return |
| 322 | } |
| 323 | |
| 324 | // We don't need a context that times out here because the ping will |
| 325 | // eventually go through. If the context times out, then other |
| 326 | // websocket read operations will receive an error, obfuscating the |
| 327 | // actual problem. |
| 328 | err := m.conn.Ping(ctx) |
| 329 | if err != nil { |
| 330 | return |
| 331 | } |
| 332 | m.lastPing.Store(ptr.Ref(time.Now())) |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | func (m *agentConnectionMonitor) updateConnectionTimes(ctx context.Context) error { |
| 337 | //nolint:gocritic // We only update the agent we are minding. |