Skip to content

Commit

Permalink
core/service/pg: fatal exit when db connection is read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Oct 3, 2023
1 parent 9a65ab2 commit 07f113e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/services/pg/lease_lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
"time"

"github.com/google/uuid"
"github.com/jackc/pgconn"
"github.com/pkg/errors"
"github.com/smartcontractkit/sqlx"
"go.uber.org/multierr"

"github.com/smartcontractkit/sqlx"

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)
Expand Down Expand Up @@ -220,6 +222,11 @@ func (l *leaseLock) loop(ctx context.Context) {
}
cancel()
if err != nil {
var pgErr pgconn.PgError
const ReadOnlyTransaction = "25006"
if errors.As(err, &pgErr) && pgErr.Code == ReadOnlyTransaction {
l.logger.Fatal("Read-only connection, exiting immediately")
}
l.logger.Errorw("Error trying to refresh database lease", "err", err)
} else if !gotLease {
if err := l.db.Close(); err != nil {
Expand Down

0 comments on commit 07f113e

Please sign in to comment.