-
Notifications
You must be signed in to change notification settings - Fork 15
Context DB txn timeout, and interface to avoid connection leak during migration #211
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
base: externalize-tag-handler
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ import ( | |
| "github.com/hyperledger/firefly-common/pkg/i18n" | ||
| "github.com/hyperledger/firefly-common/pkg/log" | ||
|
|
||
| "github.com/golang-migrate/migrate/v4/database" | ||
| // Import migrate file source | ||
| _ "github.com/golang-migrate/migrate/v4/source/file" | ||
| ) | ||
|
|
@@ -139,8 +140,17 @@ func (s *Database) RunAsGroup(ctx context.Context, fn func(ctx context.Context) | |
| return s.CommitTx(ctx, tx, false /* we _are_ the auto-committer */) | ||
| } | ||
|
|
||
| func (s *Database) applyDBMigrations(ctx context.Context, config config.Section, provider Provider) error { | ||
| driver, err := provider.GetMigrationDriver(s.db) | ||
| func (s *Database) applyDBMigrations(ctx context.Context, config config.Section, provider Provider) (err error) { | ||
| var driver database.Driver | ||
| providerClosable, isClosable := provider.(ProviderCloseableMigrationDriver) | ||
| if isClosable { | ||
| driver, err = providerClosable.GetMigrationDriverClosable(s.db) | ||
| defer func() { | ||
| _ = driver.Close() | ||
| }() | ||
| } else { | ||
| driver, err = provider.GetMigrationDriver(s.db) | ||
| } | ||
| if err == nil { | ||
| fileURL := "file://" + config.GetString(SQLConfMigrationsDirectory) | ||
| log.L(ctx).Infof("Running migrations in: %s", fileURL) | ||
|
|
@@ -184,7 +194,7 @@ func (s *Database) BeginOrUseTx(ctx context.Context) (ctx1 context.Context, tx * | |
| ctx1 = log.WithLogger(ctx, l) | ||
| before := time.Now() | ||
| l.Tracef("SQL-> begin") | ||
| sqlTX, err := s.db.Begin() | ||
| sqlTX, err := s.db.BeginTx(ctx /* transaction should auto-rollback on context cancel */, nil /* default options */) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 - this is what Opus was whispering in my ear about when analyzing this previously. Thanks makes perfect sense |
||
| if err != nil { | ||
| return ctx1, nil, false, i18n.WrapError(ctx1, err, i18n.MsgDBBeginFailed) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting - think this explains behavior I saw in some of our tests where when closing the migrations, it closed the whole driver, and caused other obscure failures in the tests 😵