MCPcopy Index your code
hub / github.com/PatchMon/PatchMon / wsLoop

Function wsLoop

agent-source-code/cmd/patchmon-agent/commands/serve.go:1355–1372  ·  view source on GitHub ↗
(out chan<- wsMsg, dockerEvents <-chan interface{})

Source from the content-addressed store, hash-verified

1353}
1354
1355func wsLoop(out chan<- wsMsg, dockerEvents <-chan interface{}) {
1356 backoff := time.Second
1357 for {
1358 // connectOnce resets backoff to 1s on successful dial so a long-lived
1359 // agent that drops its WS (e.g. Windows bouncing TermService/firewall
1360 // when RDP settings change) reconnects fast instead of waiting out the
1361 // escalated backoff from its prior drops.
1362 connected, err := connectOnce(out, dockerEvents, &backoff)
1363 if err != nil {
1364 logger.WithError(err).Warn("ws disconnected; retrying")
1365 }
1366 sleepFor := backoff
1367 if !connected && backoff < 30*time.Second {
1368 backoff *= 2
1369 }
1370 time.Sleep(sleepFor)
1371 }
1372}
1373
1374func connectOnce(out chan<- wsMsg, dockerEvents <-chan interface{}, backoff *time.Duration) (connected bool, err error) {
1375 server := cfgManager.GetConfig().PatchmonServer

Callers 1

runServiceLoopFunction · 0.85

Calls 1

connectOnceFunction · 0.85

Tested by

no test coverage detected