From 833dbf7559ec0dfbc9f8a9c7e766f464d75499a0 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 3 Oct 2023 06:35:51 -0500 Subject: [PATCH] core/service/pg: fatal exit when db connection is read-only --- core/services/pg/lease_lock.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/services/pg/lease_lock.go b/core/services/pg/lease_lock.go index 58ec2781245..f366c77e5ba 100644 --- a/core/services/pg/lease_lock.go +++ b/core/services/pg/lease_lock.go @@ -8,6 +8,7 @@ import ( "time" "github.com/google/uuid" + "github.com/jackc/pgconn" "github.com/jmoiron/sqlx" "github.com/pkg/errors" "go.uber.org/multierr" @@ -220,6 +221,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 {