Skip to content

Conversation

@nicolaj-hartmann
Copy link

Summary

When EnableLongPolling is enabled, the LISTEN connection could die from network issues without recovery, causing workers to stop processing jobs while the server heartbeat continued.

This adds automatic reconnection when the LISTEN connection fails.

Changes

  • Added inner try-catch in LISTEN loop to handle connection failures
  • Reconnects automatically after 1 second backoff
  • Swallows cleanup exceptions in Dequeue finally block

Test

Added test that kills LISTEN connection via pg_terminate_backend and verifies worker continues processing.

Fixes #410

When EnableLongPolling is enabled, the ListenForNotificationsAsync method
only caught TaskCanceledException, causing all other exceptions (network
timeouts, connection drops) to propagate up and kill the worker thread.

This change adds self-healing reconnection logic that catches connection
failures, reconnects after a 1 second backoff, and continues the loop.

Fixes hangfire-postgres#410
@nicolaj-hartmann nicolaj-hartmann force-pushed the fix/listen-connection-self-healing branch from c62568d to ca736ae Compare December 29, 2025 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Jobs stuck in Enqueued state when Postgres Listener connection is disrupted using EnableLongPolling

1 participant