diff --git a/pgconn/errors.go b/pgconn/errors.go index 3c54bbec0..619578298 100644 --- a/pgconn/errors.go +++ b/pgconn/errors.go @@ -107,14 +107,15 @@ func (e *parseConfigError) Unwrap() error { } func normalizeTimeoutError(ctx context.Context, err error) error { - if err, ok := err.(net.Error); ok && err.Timeout() { + var netErr net.Error + if errors.As(err, &netErr) && netErr.Timeout() { if ctx.Err() == context.Canceled { // Since the timeout was caused by a context cancellation, the actual error is context.Canceled not the timeout error. return context.Canceled } else if ctx.Err() == context.DeadlineExceeded { return &errTimeout{err: ctx.Err()} } else { - return &errTimeout{err: err} + return &errTimeout{err: netErr} } } return err diff --git a/pgconn/pgconn.go b/pgconn/pgconn.go index 1ccdc4db9..0203cf194 100644 --- a/pgconn/pgconn.go +++ b/pgconn/pgconn.go @@ -289,7 +289,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig pgConn.contextWatcher.Unwatch() // Always unwatch `netConn` after TLS. if err != nil { netConn.Close() - return nil, &connectError{config: config, msg: "tls error", err: err} + return nil, &connectError{config: config, msg: "tls error", err: normalizeTimeoutError(ctx, err)} } pgConn.conn = nbTLSConn