MCPcopy Index your code
hub / github.com/coder/coder / sendPings

Method sendPings

coderd/workspaceagentsrpc.go:313–334  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

311// We use a custom heartbeat routine here instead of `httpapi.Heartbeat`
312// because we want to log the agent's last ping time.
313func (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
336func (m *agentConnectionMonitor) updateConnectionTimes(ctx context.Context) error {
337 //nolint:gocritic // We only update the agent we are minding.

Callers 2

startMethod · 0.95

Calls 5

RefFunction · 0.92
StopMethod · 0.65
PingMethod · 0.65
DoneMethod · 0.45
StoreMethod · 0.45

Tested by 1