Skip to content

fix(instance-manager): add a connect timeout to the local connections - #11718

Merged
mnencia merged 3 commits into
mainfrom
dev/local-pool-connect-timeout
Oct 23, 2026
Merged

mnencia merged 3 commits into
mainfrom
dev/local-pool-connect-timeout

Conversation

@armru

@armru armru commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

The superuser and metrics exporter pools connect to PostgreSQL with no timeout, and every query opens a new connection. When the postmaster is stopped or stuck, its socket still accepts connections but never answers the startup message, so every caller blocks for good. The instance status endpoint polled by the operator is one of them. On a KIND cluster with the primary's postmaster stopped with SIGSTOP, a goroutine dump shows the pgStatus handlers blocked in pgconn.connectOne. At shutdown the :8000 web server waits for them until the controller manager gives up 30 seconds later, which delays the release of the primary lease by as much. The check that runs before an in-tree backup opens its own local connection and has the same problem, holding the backup request forever.

This sets connect_timeout=5 on these connections, as the connections to the primary already do. With #11358 applied, the same scenario releases the lease 5 seconds after the instance manager decides to exit, instead of 30. A TCP user timeout would not help: these connections go through the Unix socket, and even over TCP the kernel keeps acknowledging the data sent to a stopped postmaster.

Closes #11722

@armru
armru requested a review from a team as a code owner October 21, 2026 16:27
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.30 labels Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@armru

armru commented Oct 21, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Oct 21, 2026
@armru
armru force-pushed the dev/local-pool-connect-timeout branch from aa9214e to e86b090 Compare October 22, 2026 09:13
@armru armru changed the title fix(instance-manager): add a connect timeout to the local connection pools fix(instance-manager): add a connect timeout to the local connections Oct 22, 2026
@leonardoce
leonardoce force-pushed the dev/local-pool-connect-timeout branch from e86b090 to a2c3801 Compare October 23, 2026 10:28
@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

armru added 2 commits October 23, 2026 15:23
…pools

When the postmaster is stuck, a new local connection is accepted but
never answered, so the caller hangs forever. The status endpoint is one
such caller, and on shutdown the web server waits for it until the
manager gives up after 30 seconds, delaying the release of the primary
lease.

Use connect_timeout=5, as we already do for the primary.

Signed-off-by: Armando Ruocco <[email protected]>
The check that runs before an in-tree backup opens its own local
connection, outside the pools, so a stuck postmaster held the backup
request on the local web server forever.

Signed-off-by: Armando Ruocco <[email protected]>
@mnencia
mnencia force-pushed the dev/local-pool-connect-timeout branch from a2c3801 to a2b693e Compare October 23, 2026 13:23
Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia
mnencia merged commit 21e24f6 into main Oct 23, 2026
21 of 22 checks passed
@mnencia
mnencia deleted the dev/local-pool-connect-timeout branch October 23, 2026 14:40
cnpg-bot pushed a commit that referenced this pull request Oct 23, 2026
…#11718)

The superuser and metrics exporter pools connect to PostgreSQL with no
timeout, and every query opens a new connection. When the postmaster is
stopped or stuck, its socket still accepts connections but never answers
the startup message, so every caller blocks for good. The instance
status endpoint polled by the operator is one of them. On a KIND cluster
with the primary's postmaster stopped with SIGSTOP, a goroutine dump
shows the `pgStatus` handlers blocked in `pgconn.connectOne`. At
shutdown the `:8000` web server waits for them until the controller
manager gives up 30 seconds later, which delays the release of the
primary lease by as much. The check that runs before an in-tree backup
opens its own local connection and has the same problem, holding the
backup request forever.

This sets `connect_timeout=5` on these connections, as the connections
to the primary already do. With #11358 applied, the same scenario
releases the lease 5 seconds after the instance manager decides to exit,
instead of 30. A TCP user timeout would not help: these connections go
through the Unix socket, and even over TCP the kernel keeps
acknowledging the data sent to a stopped postmaster.

Closes #11722

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit 21e24f6)
cnpg-bot pushed a commit that referenced this pull request Oct 23, 2026
…#11718)

The superuser and metrics exporter pools connect to PostgreSQL with no
timeout, and every query opens a new connection. When the postmaster is
stopped or stuck, its socket still accepts connections but never answers
the startup message, so every caller blocks for good. The instance
status endpoint polled by the operator is one of them. On a KIND cluster
with the primary's postmaster stopped with SIGSTOP, a goroutine dump
shows the `pgStatus` handlers blocked in `pgconn.connectOne`. At
shutdown the `:8000` web server waits for them until the controller
manager gives up 30 seconds later, which delays the release of the
primary lease by as much. The check that runs before an in-tree backup
opens its own local connection and has the same problem, holding the
backup request forever.

This sets `connect_timeout=5` on these connections, as the connections
to the primary already do. With #11358 applied, the same scenario
releases the lease 5 seconds after the instance manager decides to exit,
instead of 30. A TCP user timeout would not help: these connections go
through the Unix socket, and even over TCP the kernel keeps
acknowledging the data sent to a stopped postmaster.

Closes #11722

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>
(cherry picked from commit 21e24f6)
armru added a commit that referenced this pull request Nov 17, 2026
The timeout added by #11718 is `connect_timeout=5`, which bounds the
connection attempt and not a connection that is already open.

Signed-off-by: Armando Ruocco <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases ok to merge 👌 This PR can be merged release-1.28 release-1.30

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: local connections to a stuck postmaster never time out

4 participants