Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2.9 KiB
name, description
| name | description |
|---|---|
| hangfire-startup-lock | Diagnose and recover Heimdall startup from transient Hangfire PostgreSQL recurring-job lock contention. |
Hangfire startup lock recovery
Heimdall registers all recurring jobs synchronously after database migrations in src/Heimdall.Web/Program.cs. Hangfire's PostgreSQL storage acquires a distributed lock per recurring-job id during AddOrUpdate; agent-failover is currently the first registration after removing the legacy heartbeat-monitor id.
The Central dashboard route is mapped from the same Program.cs with MapHangfireDashboard("/hangfire", ...), guarded by HangfireAdminAuthorizationFilter for Admin.Jobs or the Admin role, and omitted in Testing. When updating docs/hangfire-usage.md, verify the route and filter against these sources; do not copy a stale UseHangfireDashboard or /admin/jobs example.
Implementation and diagnosis
- Inspect the GlitchTip event stack, app start time, event timestamps, and
Program.cs/JobSetup.csline references. A timeout names the contended job key; it proves lock contention, not the number or identity of competing processes. - Because registration is on the startup path, an unhandled provider lock timeout terminates startup even when caused by another instance. Retry only
Hangfire.PostgreSql.PostgreSqlDistributedLockException; do not retry arbitrary registration/configuration failures. - Retry the complete idempotent
ConfigureRecurringJobssequence with a new DI scope per attempt. Keep delay bounded, observe application shutdown cancellation, log attempts without connection details, and propagate the final exception so missing recurring schedules are not reported as successful startup. - Cover transient recovery with a focused test that injects the provider exception and verifies a subsequent full registration attempt.
Acceptance
- Run
dotnet test tests/Heimdall.Api.Tests/Heimdall.Api.Tests.csproj --no-restore --filter FullyQualifiedName~RecurringJobStartupRetryTestsand build the Web project using the SDK pinned inglobal.json. - Run a disposable Compose project from the changed source with unique project name, generated credentials, loopback port, volume names, and a unique Heimdall image tag. Confirm the Web service becomes healthy and recurring Hangfire jobs are available in the isolated PostgreSQL storage.
- Use an EXIT trap to tear down only that Compose project, verify its containers, volumes, and networks are absent, remove and verify absence of its exact locally built image tag, and remove temporary files. Preserve the original status and report cleanup failures.
The Compose check demonstrates isolated startup and Hangfire storage integration; the synthetic unit test demonstrates contention recovery. Neither establishes that a particular production deployment had one or multiple replicas. Record deployed telemetry separately in Gitea issue #214.