Skip to content

Add Open for a pool without the startup ping - #6

Merged
Mohammed Naser (mnaser) merged 2 commits into
vexxhost:mainfrom
kingspeedy95:open-without-ping
Nov 20, 2026
Merged

Mohammed Naser (mnaser) merged 2 commits into
vexxhost:mainfrom
kingspeedy95:open-without-ping

Conversation

@kingspeedy95

@kingspeedy95 Timon Schnell (kingspeedy95) commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

ConnectContext opens the pool, pings it, and closes it again when the ping
fails. A caller that starts while its database is unreachable therefore ends up
with no pool at all, and has to build its own retry around Connect.

The OpenStack database exporter runs into exactly that: when it starts during a
database outage, it reports the affected services as down until it is
restarted, even after the database is back. Details in
vexxhost/openstack_database_exporter#150.

This adds Open, which does the URL parsing, option validation and pool setup
of ConnectContext without contacting the server. ConnectContext becomes
Open plus the ping, so Connect and ConnectContext behave as before. A pool
from Open connects on first use and again after a lost connection, which is
what database/sql already does for a pool that was pinged once.

Tests

  • TestOpenInvalidURLs and TestOpenInvalidOptions cover the same rejections
    as the Connect tests.
  • TestOpenUnreachableServer gets a pool for a port nobody listens on, checks
    the default pool limit, and checks that a ping on that pool still fails.
  • TestOpenOptions checks that the options reach the pool.
  • go test -race ./..., go vet ./..., gofmt -l . and the integration suite
    (-tags integration) pass locally.

The exporter change that uses it is ready and was tested against a production
like OpenStack control plane; it follows once this is released.

ConnectContext pings and closes the pool when the database does not
answer, so a caller that starts during a database outage has no pool
at all. The OpenStack database exporter then reports its services as
down until it is restarted, even after the database is back.

Open does the parsing and pool setup without contacting the server,
and ConnectContext becomes Open plus the ping, so existing callers
behave as before. The pool connects on first use and reconnects
after a lost connection.

Tested with go test -race, go vet, gofmt and the integration suite.

Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Timon Schnell <timon.schnell@btc-it-services.com>
Open adds no dial timeout, so a pool held through a database outage
does not fail fast. Say so in the Open doc comment and the README,
and move the Open note into its own README paragraph.

Signed-off-by: Mohammed Naser <mnaser@vexxhost.com>
@mnaser
Mohammed Naser (mnaser) merged commit 509bb72 into vexxhost:main Nov 20, 2026
5 checks passed
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.

2 participants