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

ensure conn.Close is closed #59

Merged
merged 2 commits into from
Mar 13, 2024
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
9 changes: 8 additions & 1 deletion coredb/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@
}

func (t *TxProvider) TxWithLock(ctx context.Context, lock string, durationInSec int, fn func(txContext TxContext) error) error {
dbConn, err := t.conn.Conn(ctx)
connCtx, cancel := context.WithCancel(context.Background())
dbConn, err := t.conn.Conn(connCtx)
defer func() {
cancel()
if dbConn != nil {
dbConn.Close()
}
}()
if err != nil {
return fmt.Errorf("fail to get db connection: %w", err)
}
Expand All @@ -229,7 +236,7 @@
if err == nil {
err = fmt.Errorf("release_lock failed: %w", errRelease)
} else {
err = errors.Join(err, fmt.Errorf("release_lock failed: %w", errRelease))

Check failure on line 239 in coredb/tx.go

View workflow job for this annotation

GitHub Actions / build

undefined: errors.Join
}
return
}
Expand All @@ -237,7 +244,7 @@
if err == nil {
err = newReleaseLockError(lock, durationInSec)
} else {
err = errors.Join(err, newReleaseLockError(lock, durationInSec))

Check failure on line 247 in coredb/tx.go

View workflow job for this annotation

GitHub Actions / build

undefined: errors.Join
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/mitchellh/cli v1.1.4
github.com/pkg/errors v0.9.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.1
golang.org/x/text v0.7.0
)

Expand Down Expand Up @@ -60,7 +61,6 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/src-d/go-oniguruma v1.1.0 // indirect
github.com/stretchr/testify v1.8.1 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/mod v0.7.0 // indirect
Expand Down
Loading