Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2.7 KiB
name, description
| name | description |
|---|---|
| agent-heartbeat-timeout | Diagnose and validate Central heartbeat timeouts without terminating the Heimdall Agent background service. |
Agent heartbeat timeout
AgentRegistrationService sends periodic Central heartbeats through the named Central HttpClient, whose timeout is configured in src/Heimdall.Agent/Program.cs. An HttpClient.Timeout surfaces as OperationCanceledException/TaskCanceledException, even though the host's stoppingToken is not canceled. SendHeartbeatAsync must log this as a transient timeout and return to the loop. Preserve cancellation when stoppingToken.IsCancellationRequested so host shutdown remains cooperative.
Change and test
- Keep the timeout handling local to
SendHeartbeatAsync; registration cancellation and shutdown semantics have different retry behavior. - Catch
OperationCanceledExceptiononly under!stoppingToken.IsCancellationRequested, log it as a timeout, and allow the next loop iteration to retry. The existing general exception handler continues to cover other transient failures. - In
tests/Heimdall.Agent.Tests/AgentRegistrationServiceTests.cs, use an asynchronous HTTP handler that waits on the request cancellation token. Give itsHttpClienta short timeout, then assert that a second heartbeat arrives. This verifies both the timeout source and continued service operation without waiting 10 seconds. - Run
dotnet test tests/Heimdall.Agent.Tests/Heimdall.Agent.Tests.csproj --filter FullyQualifiedName~Heartbeat_HttpTimeout_DoesNotStopService_AndNextHeartbeatSucceeds, then the full Agent test project.
Disposable Compose acceptance
Run bash skills/agent-heartbeat-timeout/acceptance.sh from the repository root. The recipe builds the Agent image from docker/Dockerfile.agent in this checkout and a small local fake Central image. The fake Central delays the first heartbeat for 12 seconds (longer than the Agent's configured 10-second Central client timeout), then accepts later heartbeats. Acceptance requires the Agent health endpoint to respond after the timeout and the fake Central to observe a subsequent heartbeat. The script uses a random Compose project, random site token, Compose-managed isolated volume/network, dynamically assigned loopback Agent port, and unique local image tags. Its EXIT trap tears down only that project, verifies its containers/volumes/networks are gone, removes and verifies absence of both exact image tags, and removes temporary files. It retains shared SDK/runtime/base images.
This synthetic recipe proves local retry behavior only. It does not validate a production runner, Central instance, or post-deployment GlitchTip telemetry; record that follow-up on Gitea issue #248.