mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-25 14:08:09 +02:00
postgres: return an empty list of addresses on dns errors
This commit is contained in:
parent
3fec00f2a8
commit
c4e5e34bdc
2 changed files with 36 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -320,7 +321,7 @@ func (backend *Backend) init(ctx context.Context) (serverVersion uint64, pool *p
|
|||
return serverVersion, pool, nil
|
||||
}
|
||||
|
||||
config, err := pgxpool.ParseConfig(backend.dsn)
|
||||
config, err := ParseConfig(backend.dsn)
|
||||
if err != nil {
|
||||
return serverVersion, nil, err
|
||||
}
|
||||
|
@ -374,3 +375,23 @@ func (backend *Backend) doPeriodically(f func(ctx context.Context) error, dur ti
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ParseConfig parses a DSN into a pgxpool.Config.
|
||||
func ParseConfig(dsn string) (*pgxpool.Config, error) {
|
||||
config, err := pgxpool.ParseConfig(dsn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.ConnConfig.LookupFunc = lookup
|
||||
return config, nil
|
||||
}
|
||||
|
||||
func lookup(ctx context.Context, host string) (addrs []string, err error) {
|
||||
addrs, err = net.DefaultResolver.LookupHost(ctx, host)
|
||||
// ignore no such host errors
|
||||
if e := new(net.DNSError); errors.As(err, &e) && e.IsNotFound {
|
||||
addrs = nil
|
||||
err = nil
|
||||
}
|
||||
return addrs, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue