Skip to content

Commit

Permalink
Actually retry every database error, including "pq: ..."
Browse files Browse the repository at this point in the history
They aren't of type *pq.Error, but they're clearly database errors.
  • Loading branch information
Al2Klimov authored and oxzi committed Sep 10, 2024
1 parent 296f480 commit 00aae3d
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions retry/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pkg/errors"
"io"
"net"
"strings"
"syscall"
"time"
)
Expand Down Expand Up @@ -197,5 +198,11 @@ func Retryable(err error) bool {
return true
}

// For errors without a five-digit code, github.com/lib/pq uses fmt.Errorf().
// That returns an unexported error type, so we can only check the error message:
if strings.HasPrefix(err.Error(), "pq: ") {
return true
}

return false
}

0 comments on commit 00aae3d

Please sign in to comment.