From 0c1c4e897ae6f2e16b86d3babd3a91e2bd16ad0a Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Wed, 29 Nov 2023 18:35:58 -0600 Subject: [PATCH] Adding contextDeadlineExceeded check to WithTx --- database/sql.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/database/sql.go b/database/sql.go index ce4e5ab..f8bd74c 100644 --- a/database/sql.go +++ b/database/sql.go @@ -58,7 +58,8 @@ func WithTx(ctx context.Context, opts *sql.TxOptions, fn func(tx *sql.Tx) error) txErr = tx.Commit() } - if errors.Is(err, context.Canceled) && errors.Is(txErr, sqldriver.ErrBadConn) { + if (errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)) && + errors.Is(txErr, sqldriver.ErrBadConn) { // When a query fails because the context has been canceled, pq will // return "driver: bad connection" from tx.Rollback. Do not panic in // this case. See https://github.com/lib/pq/issues/1137 -- 2.45.2