Skip to content

Commit

Permalink
Retry every github.com/lib/pq database error, including "pq: ..."
Browse files Browse the repository at this point in the history
Some errors created within github.com/lib/pq are created with
fmt.Errorf, prefixed with "pq: ". Thus, they are not of the *pq.Error
type, but are clearly database errors.

A change request was created upstream in:
lib/pq#1169

Co-Authored-By: Alvar Penning <[email protected]>
  • Loading branch information
Al2Klimov and oxzi committed Sep 24, 2024
1 parent 296f480 commit 2eab550
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 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,12 @@ func Retryable(err error) bool {
return true
}

// For errors without a five-digit code, github.com/lib/pq uses fmt.Errorf().
// This returns an unexported error type prefixed with "pq: "
// Until this gets changed upstream <https://github.com/lib/pq/issues/1169>, we can only check the error message.
if strings.HasPrefix(err.Error(), "pq: ") {
return true
}

return false
}

0 comments on commit 2eab550

Please sign in to comment.