Files
Heimdall/skills/hangfire-startup-lock/SKILL.md
T
arnaud.dartois 021bdecab3
Heimdall Gitea / Detect CI scope (push) Successful in 4s
Heimdall Gitea / Build and tests (push) Skipped
Heimdall Gitea / Build and scan server image (push) Skipped
Heimdall Gitea / Build and scan agent image (push) Skipped
Heimdall Gitea / Build and scan NVIDIA Agent image (push) Skipped
Heimdall Gitea / Publish versioned installer release (push) Skipped
Heimdall Gitea / CI policy (push) Successful in 1s
docs: align Hangfire dashboard guide with route (#370)
Co-authored-by: Arnaud Dartois <admin@tordais.cc>
2026-11-13 10:38:44 +01:00

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.cs line 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 ConfigureRecurringJobs sequence 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

  1. Run dotnet test tests/Heimdall.Api.Tests/Heimdall.Api.Tests.csproj --no-restore --filter FullyQualifiedName~RecurringJobStartupRetryTests and build the Web project using the SDK pinned in global.json.
  2. 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.
  3. 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.