Skip to content
Snippets Groups Projects

dbconn: stop leaking DB connections everytime we migrate

Closed Warren Gifford 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 stephen@sourcegraph.com

Merge request reports

Closed by avatar (Jul 13, 2025 1:42pm UTC)

Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
Please register or sign in to reply
Loading