Skip to content

Commit

Permalink
modify connect method again to avoid returning values
Browse files Browse the repository at this point in the history
  • Loading branch information
ikehara committed Jul 2, 2024
1 parent 7c73f23 commit abdbcfd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions proxycore/connpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,37 +138,39 @@ func (p *connPool) connect() (conn *ClientConn, err error) {
PreparedCache: p.preparedCache,
Logger: p.logger})
if err != nil {
return nil, err
return
}

defer func() {
if err != nil && conn != nil {
_ = conn.Close()
conn = nil
}
}()

var version primitive.ProtocolVersion
version, err = conn.Handshake(ctx, p.config.Version, p.config.Auth)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
return nil, fmt.Errorf("handshake took longer than %s to complete", p.config.ConnectTimeout)
err = fmt.Errorf("handshake took longer than %s to complete", p.config.ConnectTimeout)
}
return conn, err
return
}
if version != p.config.Version {
p.logger.Error("protocol version not support", zap.Stringer("wanted", p.config.Version), zap.Stringer("got", version))
return conn, ProtocolNotSupported
err = ProtocolNotSupported
return
}

if len(p.config.Keyspace) != 0 {
err = conn.SetKeyspace(ctx, p.config.Version, p.config.Keyspace)
if err != nil {
return conn, err
return
}
}

go conn.Heartbeats(p.config.ConnectTimeout, p.config.Version, p.config.HeartBeatInterval, p.config.IdleTimeout, p.logger)
return conn, nil
return
}

// stayConnected will attempt to reestablish a disconnected (`connection == nil`) connection within the pool. Reconnect attempts
Expand Down

0 comments on commit abdbcfd

Please sign in to comment.