diff options
Diffstat (limited to 'vendor/github.com/jackc/pgconn')
-rw-r--r-- | vendor/github.com/jackc/pgconn/CHANGELOG.md | 7 | ||||
-rw-r--r-- | vendor/github.com/jackc/pgconn/README.md | 6 | ||||
-rw-r--r-- | vendor/github.com/jackc/pgconn/config.go | 13 | ||||
-rw-r--r-- | vendor/github.com/jackc/pgconn/pgconn.go | 23 |
4 files changed, 41 insertions, 8 deletions
diff --git a/vendor/github.com/jackc/pgconn/CHANGELOG.md b/vendor/github.com/jackc/pgconn/CHANGELOG.md index f6a6807f0..3550b437e 100644 --- a/vendor/github.com/jackc/pgconn/CHANGELOG.md +++ b/vendor/github.com/jackc/pgconn/CHANGELOG.md @@ -1,3 +1,10 @@ +# 1.14.0 (February 11, 2023) + +* Fix: each connection attempt to new node gets own timeout (Nathan Giardina) +* Set SNI for SSL connections (Stas Kelvich) +* Fix: CopyFrom I/O race (Tommy Reilly) +* Minor dependency upgrades + # 1.13.0 (August 6, 2022) * Add sslpassword support (Eric McCormack and yun.xu) diff --git a/vendor/github.com/jackc/pgconn/README.md b/vendor/github.com/jackc/pgconn/README.md index 1c698a118..9af04fe74 100644 --- a/vendor/github.com/jackc/pgconn/README.md +++ b/vendor/github.com/jackc/pgconn/README.md @@ -1,6 +1,12 @@ [](https://godoc.org/github.com/jackc/pgconn)  +--- + +This version is used with pgx `v4`. In pgx `v5` it is part of the https://github.com/jackc/pgx repository. + +--- + # pgconn Package pgconn is a low-level PostgreSQL database driver. It operates at nearly the same level as the C library libpq. diff --git a/vendor/github.com/jackc/pgconn/config.go b/vendor/github.com/jackc/pgconn/config.go index 2277dc1de..4080f2c6a 100644 --- a/vendor/github.com/jackc/pgconn/config.go +++ b/vendor/github.com/jackc/pgconn/config.go @@ -297,6 +297,7 @@ func ParseConfigWithOptions(connString string, options ParseConfigOptions) (*Con "sslcert": {}, "sslrootcert": {}, "sslpassword": {}, + "sslsni": {}, "krbspn": {}, "krbsrvname": {}, "target_session_attrs": {}, @@ -424,6 +425,7 @@ func parseEnvSettings() map[string]string { "PGSSLMODE": "sslmode", "PGSSLKEY": "sslkey", "PGSSLCERT": "sslcert", + "PGSSLSNI": "sslsni", "PGSSLROOTCERT": "sslrootcert", "PGSSLPASSWORD": "sslpassword", "PGTARGETSESSIONATTRS": "target_session_attrs", @@ -619,11 +621,15 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P sslcert := settings["sslcert"] sslkey := settings["sslkey"] sslpassword := settings["sslpassword"] + sslsni := settings["sslsni"] // Match libpq default behavior if sslmode == "" { sslmode = "prefer" } + if sslsni == "" { + sslsni = "1" + } tlsConfig := &tls.Config{} @@ -756,6 +762,13 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P tlsConfig.Certificates = []tls.Certificate{cert} } + // Set Server Name Indication (SNI), if enabled by connection parameters. + // Per RFC 6066, do not set it if the host is a literal IP address (IPv4 + // or IPv6). + if sslsni == "1" && net.ParseIP(host) == nil { + tlsConfig.ServerName = host + } + switch sslmode { case "allow": return []*tls.Config{nil, tlsConfig}, nil diff --git a/vendor/github.com/jackc/pgconn/pgconn.go b/vendor/github.com/jackc/pgconn/pgconn.go index 17f19e955..6601194ce 100644 --- a/vendor/github.com/jackc/pgconn/pgconn.go +++ b/vendor/github.com/jackc/pgconn/pgconn.go @@ -128,19 +128,13 @@ func ConnectWithOptions(ctx context.Context, connString string, parseConfigOptio // authentication error will terminate the chain of attempts (like libpq: // https://www.postgresql.org/docs/11/libpq-connect.html#LIBPQ-MULTIPLE-HOSTS) and be returned as the error. Otherwise, // if all attempts fail the last error is returned. -func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err error) { +func ConnectConfig(octx context.Context, config *Config) (pgConn *PgConn, err error) { // Default values are set in ParseConfig. Enforce initial creation by ParseConfig rather than setting defaults from // zero values. if !config.createdByParseConfig { panic("config must be created by ParseConfig") } - // ConnectTimeout restricts the whole connection process. - if config.ConnectTimeout != 0 { - var cancel context.CancelFunc - ctx, cancel = context.WithTimeout(ctx, config.ConnectTimeout) - defer cancel() - } // Simplify usage by treating primary config and fallbacks the same. fallbackConfigs := []*FallbackConfig{ { @@ -150,7 +144,7 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err }, } fallbackConfigs = append(fallbackConfigs, config.Fallbacks...) - + ctx := octx fallbackConfigs, err = expandWithIPs(ctx, config.LookupFunc, fallbackConfigs) if err != nil { return nil, &connectError{config: config, msg: "hostname resolving error", err: err} @@ -163,6 +157,14 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err foundBestServer := false var fallbackConfig *FallbackConfig for _, fc := range fallbackConfigs { + // ConnectTimeout restricts the whole connection process. + if config.ConnectTimeout != 0 { + var cancel context.CancelFunc + ctx, cancel = context.WithTimeout(octx, config.ConnectTimeout) + defer cancel() + } else { + ctx = octx + } pgConn, err = connect(ctx, config, fc, false) if err == nil { foundBestServer = true @@ -1252,8 +1254,11 @@ func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (Co abortCopyChan := make(chan struct{}) copyErrChan := make(chan error, 1) signalMessageChan := pgConn.signalMessage() + var wg sync.WaitGroup + wg.Add(1) go func() { + defer wg.Done() buf := make([]byte, 0, 65536) buf = append(buf, 'd') sp := len(buf) @@ -1307,6 +1312,8 @@ func (pgConn *PgConn) CopyFrom(ctx context.Context, r io.Reader, sql string) (Co } } close(abortCopyChan) + // Make sure io goroutine finishes before writing. + wg.Wait() buf = buf[:0] if copyErr == io.EOF || pgErr != nil { |