Skip to content

Comments

Harden Postgresql AdvisoryLock against closed connections during shutdown#2172

Merged
jeremydmiller merged 1 commit intomainfrom
GH2146
Feb 12, 2026
Merged

Harden Postgresql AdvisoryLock against closed connections during shutdown#2172
jeremydmiller merged 1 commit intomainfrom
GH2146

Conversation

@jeremydmiller
Copy link
Member

Summary

  • Catch exceptions in ReleaseLockAsync when the underlying connection is broken during shutdown, preventing NpgsqlException: Exception while reading from stream
  • Check ConnectionState.Open before attempting to release locks or close the connection in DisposeAsync, preventing InvalidOperationException: Connection is not open
  • Fix double-dispose bug where DisposeAsync was called on the connection in both catch and finally blocks
  • Extract safeCloseConnectionAsync() helper that guards all close/dispose operations with state checks and try/catch
  • No exception can escape DisposeAsync

Closes #2146

Test plan

  • Verify Postgresql persistence tests still pass
  • Confirm graceful shutdown no longer throws advisory lock errors in multi-replica deployments

🤖 Generated with Claude Code

…down

Catch exceptions in ReleaseLockAsync and DisposeAsync when the
connection is already broken or closed, which occurs during graceful
shutdown in multi-replica environments. Fixes double-dispose bug and
checks connection state before attempting close operations.

Closes GH-2146

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Transactional inbox/outbox via psql with multiple replicas: Fails to gracefully shutdown, Error trying to release the leadership lock

1 participant