pgx.Rows can leak on the relation-not-found retry path in startQueryWithRetries
pgx.Rows returned by a failed query can leak in startQueryWithRetries's relation-not-found retry path.
Where: pkg/db/db_client/db_client_execute_retry.go, startQueryWithRetries, and db_client_execute.go, startQuery.
What happens today: startQuery returns rows as a named return even on error (pgx requires Rows to be closed even when Query itself returned an error). startQueryWithRetries never closes it on the retry/error path, so rows leaks on every "relation not found" retry iteration.
Already discovered and worth keeping in mind for the real fix: a first attempt at this fix (unconditional rows.Close() on the error path) introduced a nil-pointer panic - rows can still be nil on that path, specifically when startQuery returns early on ctx.Done() before its internal goroutine has assigned the named return (i.e. on every query cancellation or timeout while a query is in flight). Any real fix needs a nil guard before Close().
What a fix would change for users: none directly (it's a resource-cleanup fix), but it needs regression coverage for both the normal retry path and the cancellation-mid-query path together, since fixing one without the other reintroduces a crash instead of a leak.
What analysis is needed before fixing: whether pgx.Conn.Query/cancellation timing can be exercised in a unit test without a live postgres connection (pgx has no official mock), or whether this needs an acceptance-level test instead.
Generated with Claude Code
Source: turbot/steampipe