Skip to content

Explicit Postgres connection cleanup on graceful shutdown #3284

@balegas

Description

@balegas

During graceful shutdowns, Electric doesn't explicitly clean up its Postgres backend connections. We've had issues where we've seen hanging connections and we can't quite explain why. We want to explicitly shutdown the connection to prevent any potential inconsistent states. While this doesn't address crash scenarios, it might help preventing accumulation of stale connections during normal deployment cycles and planned restarts .

Proposed Solution: Track backend PIDs and explicitly terminate them during shutdown sequence using a separate pool connection.

Requirements

  • Capture Postgres backend conneciton PID when establishing replication connection
  • On graceful shutdown, terminate the backend process
  • Defensively clean up replication slots before termination
  • Ensure cleanup happens before releasing advisory lock

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions