c/agent: add timeout to Heartbeat RPCs
gRPC recommends adding a deadline or timeout to all RPCs, let's also do
that here to avoid a single RPC from taking too long and causing the
agent to be restarted because it missed a heartbeat.
Change-Id: I99b413ce09fbfba93f1fc49fc5ca2da440f0d30e
Reviewed-on: https://review.monogon.dev/c/monogon/+/1590
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/cloud/agent/agent.go b/cloud/agent/agent.go
index e6722d5..a339794 100644
--- a/cloud/agent/agent.go
+++ b/cloud/agent/agent.go
@@ -126,7 +126,9 @@
if installationReport != nil {
req.InstallationReport = installationReport
}
- res, err := c.Heartbeat(context.Background(), &req)
+ reqCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
+ res, err := c.Heartbeat(reqCtx, &req)
+ cancel()
if err != nil {
l.Infof("Heartbeat failed: %v", err)
time.Sleep(b.NextBackOff())