From c3605107cd83e4047bc846d748b7073f735bb84b Mon Sep 17 00:00:00 2001 From: Rafi Shamim Date: Thu, 16 Nov 2023 06:21:38 +0000 Subject: [PATCH] roachtest: lower connection timeout and include node ID This adds two improvements to help with debugging: - Include the node ID in the message if we fail to connect to a node. - Fix the connection timeout at 1 minute rather than leaving it infinite. Release note: None --- pkg/cmd/roachtest/cluster.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/roachtest/cluster.go b/pkg/cmd/roachtest/cluster.go index 7b520635f503..32a883305cbb 100644 --- a/pkg/cmd/roachtest/cluster.go +++ b/pkg/cmd/roachtest/cluster.go @@ -2550,7 +2550,9 @@ func (c *clusterImpl) Conn( // ConnE returns a SQL connection to the specified node. func (c *clusterImpl) ConnE( ctx context.Context, l *logger.Logger, node int, opts ...func(*option.ConnOption), -) (*gosql.DB, error) { +) (_ *gosql.DB, retErr error) { + // NB: errors.Wrap returns nil if err is nil. + defer func() { retErr = errors.Wrapf(retErr, "connecting to node %d", node) }() connOptions := &option.ConnOption{} for _, opt := range opts { @@ -2580,6 +2582,9 @@ func (c *clusterImpl) ConnE( for k, v := range connOptions.Options { vals.Add(k, v) } + // connect_timeout is a libpq-specific parameter for the maximum wait for + // connection, in seconds. + vals.Add("connect_timeout", "60") dataSourceName = dataSourceName + "&" + vals.Encode() } db, err := gosql.Open("postgres", dataSourceName)