Adding contextDeadlineExceeded check to WithTx
1 files changed, 2 insertions(+), 1 deletions(-)

M database/sql.go
M database/sql.go +2 -1
@@ 58,7 58,8 @@ func WithTx(ctx context.Context, opts *s
 		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