jackc / jackc/pgx

error when providing multiple endpoints to pgpool.Connect()

Open
#1,721 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
14.3k
Forks
1.1k
Avg merge
6d 9h
Merged PRs (30d)
11

Description

This bug originated from the discussion here: https://github.com/jackc/pgx/discussions/1711#discussioncomment-6768568

Provide multiple endpoints to pgpool.Connect() via connection string. Set the first host to a hostname that doesn't exist. Expected behavior is that when pgpool.Connect() attempts connection to the first host, upon failing to connect, should move onto the next host to attempt connection until a connection is made or there are no more hosts provided. This is to be consistent with libpq's behavior.
Issue is that 'hostname resolving error' is returned and there is no attempt to connect to the other hosts.

```
var connectStr = "postgres://postgres@test-database-server:6000,test-database-server:5432,172.17.0.30:6000,172.17.0.37:5432/postgres"
func ConnectDB(retryInterval int) {
setupOnce.Do(func() {
context := context.Background()
pool, connErr := pgxpool.Connect(context, connectStr)

for connErr != nil {
Logger.Pac_Info_f("Unable to connect to database: %v\n", connErr)
time.Sleep(time.Duration(retryInterval) * time.Second)
Logger.Pac_Info("Reconnecting to Database...")
pool, connErr = pgxpool.Connect(context, connectStr)
}
Logger.Pac_Info_f("Connected to database: %v\n", connectStr)

SetupDBPool(pool, context)
})
}
```

**Version**
- Go: 1.17.1
- PostgreSQL: 13.7
- pgx: 4.17.2

Contributor guide

Open the contributing guide

Research direction

Start at pgxpool.Connect() and its connection-string handling, using the example with an invalid first hostname and multiple endpoints. Confirm that hostname resolution failure advances to later hosts, and that connection succeeds when a later endpoint is available, matching the described libpq behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, postgresql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.