Skip to content

dbconn: stop leaking DB connections everytime we migrate

Administrator requested to merge sg/stop-leaking-db-handles into main

Created by: slimsag

This will probably help a bit with our "DB connections is too low" issue...

Prior to this change, any call to dbconn.MigrateDB would leak a DB connection. This is because dbconn.NewMigrate duplicates the connection:

	driver, err := postgres.WithInstance(db, &postgres.Config{
		MigrationsTable: database.MigrationsTable,
	})

I only caught this because I was writing test code which tried to migrate the code insights database, and then drop the database I created for a test. It always failed, despite my cleanup code working correctly:

dropping test database ERROR: database "insights_test_testresolver_insights" is being accessed by other users (SQLSTATE 55006)

It turned out that commenting out dbconn.MigrateDB fixed it - leading me to find this bug.

Signed-off-by: Stephen Gutekanst [email protected]

Merge request reports

Loading