Skip to content

Commit 6ed9700

Browse files
feat(cloudsqlpg): run SELECT 1 after successful connection attempt (#2997)
## Description > Should include a concise description of the changes (bug or feature), it's > impact, along with a summary of the solution Update the initialization logic to execute a "SELECT 1" statement immediately after a successful ping. This confirms that the database engine is not only reachable but also ready to parse and execute SQL commands. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [x] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [x] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [x] Ensure the tests and linter pass - [x] Code coverage does not decrease (if any source code was changed) - [x] Appropriate docs were updated (if necessary) - [x] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #2996
1 parent 620eaed commit 6ed9700

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎internal/sources/cloudsqlpg/cloud_sql_pg.go‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,17 @@ func (r Config) Initialize(ctx context.Context, tracer trace.Tracer) (sources.So
7171

7272
err = pool.Ping(ctx)
7373
if err != nil {
74+
pool.Close()
7475
return nil, fmt.Errorf("unable to connect successfully: %w", err)
7576
}
7677

78+
var res int
79+
err = pool.QueryRow(ctx, "SELECT 1").Scan(&res)
80+
if err != nil {
81+
pool.Close()
82+
return nil, fmt.Errorf("failed to execute 'SELECT 1' after connection: %w", err)
83+
}
84+
7785
s := &Source{
7886
Config: r,
7987
Pool: pool,

0 commit comments

Comments
 (0)