Skip to content

test: pin that open_connections is never negative under dial+immediate close - #1184

Open
panavenue wants to merge 1 commit into
feature/client-side-metricsfrom
metrics-open-conns-test
Open

panavenue wants to merge 1 commit into
feature/client-side-metricsfrom
metrics-open-conns-test

Conversation

@panavenue

Copy link
Copy Markdown
Collaborator

Follow-up to the AlloyDB finding in GoogleCloudPlatform/alloydb-go-connector#820 (open_connections could go negative because the OTel increment ran in a goroutine while the decrement in instrumentedConn.Close was synchronous).

Cloud SQL does not have the bug: every OpenTelemetry record on the dial path is synchronous and happens before the net.Conn is returned, so a decrement cannot precede its increment (dialer.go success path: RecordOpenConnection → RecordConnectLatencies → RecordOpenConnectionCount → return; closeFunc can only run afterwards).

This PR adds a regression test only: 20 dial + immediate close pairs against the mock instance, then asserts every exported open_connections point is 0. Verified that temporarily moving the increment into a goroutine (as AlloyDB had) makes it fail with open_connections exported -1.

No production code changes.

…e close

The AlloyDB connector hit a race (alloydb-go-connector#820) where the
OpenTelemetry open_connections increment ran in a background goroutine
while the decrement in instrumentedConn.Close was synchronous, so prompt
closes drove the up/down counter negative. The Cloud SQL dial path
records all OpenTelemetry measurements synchronously and in order, so
the bug does not apply here; this test guards against introducing it.
Verified the test fails (-1) if the increment is moved into a goroutine.
@panavenue
panavenue force-pushed the metrics-open-conns-test branch from 80d4a4d to d90ea95 Compare October 23, 2026 04:19
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