Skip to content

Commit

Permalink
Merge pull request #287 from cnnrznn/cnnrznn_protocol_version
Browse files Browse the repository at this point in the history
Set protocol version inside connectAttemptOne
  • Loading branch information
cole-miller authored Feb 21, 2024
2 parents 64838e2 + d0c4bc5 commit dfa1d3a
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/protocol/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,7 @@ func (c *Connector) connectAttemptAll(ctx context.Context, log logging.Func) (*P
ctx, cancel := context.WithTimeout(ctx, c.config.AttemptTimeout)
defer cancel()

version := VersionOne
protocol, leader, err := c.connectAttemptOne(ctx, server.Address, version)
if err == errBadProtocol {
log(logging.Warn, "unsupported protocol %d, attempt with legacy", version)
version = VersionLegacy
protocol, leader, err = c.connectAttemptOne(ctx, server.Address, version)
}
protocol, leader, err := c.connectAttemptOne(ctx, server.Address, log)
if err != nil {
// This server is unavailable, try with the next target.
log(logging.Warn, err.Error())
Expand All @@ -168,7 +162,7 @@ func (c *Connector) connectAttemptAll(ctx context.Context, log logging.Func) (*P
ctx, cancel = context.WithTimeout(ctx, c.config.AttemptTimeout)
defer cancel()

protocol, leader, err = c.connectAttemptOne(ctx, leader, version)
protocol, _, err = c.connectAttemptOne(ctx, leader, log)
if err != nil {
// The leader reported by the previous server is
// unavailable, try with the next target.
Expand Down Expand Up @@ -220,7 +214,7 @@ func Handshake(ctx context.Context, conn net.Conn, version uint64) (*Protocol, e
// - Target not leader and no leader known: -> nil, "", nil
// - Target not leader and leader known: -> nil, leader, nil
// - Target is the leader: -> server, "", nil
func (c *Connector) connectAttemptOne(ctx context.Context, address string, version uint64) (*Protocol, string, error) {
func (c *Connector) connectAttemptOne(ctx context.Context, address string, log logging.Func) (*Protocol, string, error) {
dialCtx, cancel := context.WithTimeout(ctx, c.config.DialTimeout)
defer cancel()

Expand All @@ -230,7 +224,13 @@ func (c *Connector) connectAttemptOne(ctx context.Context, address string, versi
return nil, "", errors.Wrap(err, "dial")
}

version := VersionOne
protocol, err := Handshake(ctx, conn, version)
if err == errBadProtocol {
log(logging.Warn, "unsupported protocol %d, attempt with legacy", version)
version = VersionLegacy
protocol, err = Handshake(ctx, conn, version)
}
if err != nil {
conn.Close()
return nil, "", err
Expand Down

0 comments on commit dfa1d3a

Please sign in to comment.