From 53c11d173a79ae5c004871b1b5840c6f9425a080 Mon Sep 17 00:00:00 2001 From: Kang Ming Date: Tue, 20 Aug 2024 07:46:18 -0400 Subject: [PATCH] fix: ignore errors if transaction has closed already (#1726) --- internal/storage/dial.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/storage/dial.go b/internal/storage/dial.go index 274a06a2cf..16cd75c989 100644 --- a/internal/storage/dial.go +++ b/internal/storage/dial.go @@ -145,7 +145,13 @@ func (c *Connection) Transaction(fn func(*Connection) error) error { return err } }); terr != nil { - return terr + // there exists a race condition when the context deadline is exceeded + // and whether the transaction has been committed or not + // e.g. if the context deadline has exceeded but the transaction has already been committed, + // it won't be possible to perform a rollback on the transaction since the transaction has been closed + if !errors.Is(terr, sql.ErrTxDone) { + return terr + } } return returnErr }