~netlandish/gobwebs

0c1c4e897ae6f2e16b86d3babd3a91e2bd16ad0a — Peter Sanchez 11 months ago 088ee45
Adding contextDeadlineExceeded check to WithTx
1 files changed, 2 insertions(+), 1 deletions(-)

M database/sql.go
M database/sql.go => database/sql.go +2 -1
@@ 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