Skip to content

Half-open PostgreSQL sessions after up -d recreates the control plane's network namespace #429

Done

Description

@samuelmbabhazi

What happens

docker compose up -d with a new control plane image recreates net, the container whose network namespace the control plane and Caddy share (network_mode: service:net). The old control plane loses its network before its process ends. Its PostgreSQL connections then never send their end, and PostgreSQL keeps them as idle sessions. Without TCP keepalives, they stay until the kernel's default timeout, about two hours.

Seen on the lab on 2026-11-23, while testing #427:

  • after up -d swapped the image, 3 shipkeep_app sessions (one of them pg-boss) stayed open from the old namespace's address, which no container used any more;
  • backup.sh restore then failed at the rename with database "shipkeep" is being accessed by other users.

#427 now ends such sessions before the rename, since the control plane is stopped at that point. The sessions themselves remain a problem:

  • they hold connection slots after every upgrade (docker compose pull && docker compose up -d, INSTALL.md "Upgrade");
  • they block anything else that needs the database to itself.

Proposed fix

  • Enable server-side TCP keepalives on PostgreSQL in deploy/control-plane/compose.yml, for example -c tcp_keepalives_idle=60 -c tcp_keepalives_interval=10 -c tcp_keepalives_count=6, so that half-open sessions end within about two minutes.
  • Check whether the recreation order can stop the control plane before net. This is the cleaner fix, if Compose allows it.
  • Test it: run up -d with a new image, then check pg_stat_activity for sessions from the old address after the keepalive delay.

Related: #240 (upgrades), #427.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions