Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

internal: ensure schema manager is closed #5521

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/cmd/commands/database/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ func migrateDatabase(ctx context.Context, ui cli.Ui, dialect, u string, initiali
// This is an advisory lock on the DB which is released when the DB session ends.
if err := man.ExclusiveLock(ctx); err != nil {
ui.Error("Unable to capture a lock on the database.")
_ = man.Close(ctx)
return noop, 2
}
unlock := func() {
// We don't report anything since this should resolve itself anyways.
_ = man.ExclusiveUnlock(ctx)
_ = man.Close(ctx)
}

st, err := man.CurrentState(ctx)
Expand Down
1 change: 1 addition & 0 deletions internal/db/schema/migrations/oss/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func ApplyMigration(t *testing.T, ctx context.Context, d *sql.DB, migrationId in
schema.TestCreatePartialEditions(schema.Dialect(dialect), schema.PartialEditions{"oss": migrationId}),
))
require.NoError(t, err)
t.Cleanup(func() { m.Close(context.Background()) })
_, err = m.ApplyMigrations(ctx)
require.NoError(t, err)
state, err := m.CurrentState(ctx)
Expand Down
1 change: 1 addition & 0 deletions internal/db/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func MigrateStore(ctx context.Context, dialect Dialect, url string, opt ...Optio
if err != nil {
return false, errors.Wrap(ctx, err, op)
}
defer sMan.Close(ctx)

st, err := sMan.CurrentState(ctx)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/oplog/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func testInitStore(t testing.TB, cleanup func() error, url string) {
require.NoError(t, err)
sm, err := schema.NewManager(ctx, schema.Dialect(dialect), d)
require.NoError(t, err)
t.Cleanup(func() { sm.Close(context.Background()) })
_, err = sm.ApplyMigrations(ctx)
require.NoError(t, err)
}
Expand Down
Loading