Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions internal/flypg/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"strconv"
"strings"
"time"

"github.com/fly-apps/postgres-flex/internal/flypg/admin"
Expand Down Expand Up @@ -216,7 +217,13 @@ func (n *Node) PostInit(ctx context.Context) error {
// Use the Postgres user on boot, since our internal user may not have been created yet.
conn, err := n.NewLocalConnection(ctx, "postgres", n.OperatorCredentials)
if err != nil {
return fmt.Errorf("failed to establish connection to member: %s", err)
// Check to see if this is an authentication error.
if strings.Contains(err.Error(), "28P01") {
fmt.Println("WARNING: `postgres` user password does not match the `OPERATOR_PASSWORD` secret")
fmt.Printf("HINT: Use `fly secrets set OPERATOR_PASSWORD=<password> --app %s` to resolve the issue\n", n.AppName)
}

return fmt.Errorf("failed to establish connection to local node: %s", err)
}
defer func() { _ = conn.Close(ctx) }()

Expand Down Expand Up @@ -283,6 +290,11 @@ func (n *Node) PostInit(ctx context.Context) error {
default:
return fmt.Errorf("member has unknown role: %q", member.Role)
}

// Ensure connection is closed.
if err := repConn.Close(ctx); err != nil {
return fmt.Errorf("failed to close connection: %s", err)
}
} else {
// New member

Expand Down Expand Up @@ -335,11 +347,6 @@ func (n *Node) PostInit(ctx context.Context) error {
if err := issueRegistrationCert(); err != nil {
return fmt.Errorf("failed to issue registration certificate: %s", err)
}

// Ensure connection is closed.
if err := conn.Close(ctx); err != nil {
return fmt.Errorf("failed to close connection: %s", err)
}
} else {
// Configure as standby
fmt.Println("Registering standby")
Expand All @@ -354,6 +361,11 @@ func (n *Node) PostInit(ctx context.Context) error {
}
}

// Ensure connection is closed.
if err := conn.Close(ctx); err != nil {
return fmt.Errorf("failed to close connection: %s", err)
}

return nil
}

Expand Down