Context DB txn timeout, and interface to avoid connection leak during migration#211
Open
peterbroadhurst wants to merge 1 commit intoexternalize-tag-handlerfrom
Open
Context DB txn timeout, and interface to avoid connection leak during migration#211peterbroadhurst wants to merge 1 commit intoexternalize-tag-handlerfrom
peterbroadhurst wants to merge 1 commit intoexternalize-tag-handlerfrom
Conversation
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
onelapahead
approved these changes
Mar 17, 2026
| 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.
👍🏻 - this is what Opus was whispering in my ear about when analyzing this previously. Thanks makes perfect sense
Comment on lines
+144
to
+153
| 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) | ||
| } |
Contributor
There was a problem hiding this comment.
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 😵
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This addresses two issues with the DB driver:
Beginwe're not supplying the context to allow the DB to automatically terminate the transaction when the context expiresWithInstancefunction would close the whole DB if we useddriver.Close()WithConnection()in the migration driver for PostgreSQLWithConnection()