Skip to content

Commit 181da40

Browse files
committed
modify connect method again to avoid returning values
1 parent 7c73f23 commit 181da40

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

proxycore/connpool.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -138,37 +138,39 @@ func (p *connPool) connect() (conn *ClientConn, err error) {
138138
PreparedCache: p.preparedCache,
139139
Logger: p.logger})
140140
if err != nil {
141-
return nil, err
141+
return
142142
}
143143

144144
defer func() {
145145
if err != nil && conn != nil {
146146
_ = conn.Close()
147+
conn = nil
147148
}
148149
}()
149150

150151
var version primitive.ProtocolVersion
151152
version, err = conn.Handshake(ctx, p.config.Version, p.config.Auth)
152153
if err != nil {
153154
if errors.Is(err, context.DeadlineExceeded) {
154-
return nil, fmt.Errorf("handshake took longer than %s to complete", p.config.ConnectTimeout)
155+
err = fmt.Errorf("handshake took longer than %s to complete", p.config.ConnectTimeout)
155156
}
156-
return conn, err
157+
return
157158
}
158159
if version != p.config.Version {
159160
p.logger.Error("protocol version not support", zap.Stringer("wanted", p.config.Version), zap.Stringer("got", version))
160-
return conn, ProtocolNotSupported
161+
err = ProtocolNotSupported
162+
return
161163
}
162164

163165
if len(p.config.Keyspace) != 0 {
164166
err = conn.SetKeyspace(ctx, p.config.Version, p.config.Keyspace)
165167
if err != nil {
166-
return conn, err
168+
return
167169
}
168170
}
169171

170172
go conn.Heartbeats(p.config.ConnectTimeout, p.config.Version, p.config.HeartBeatInterval, p.config.IdleTimeout, p.logger)
171-
return conn, nil
173+
return
172174
}
173175

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

0 commit comments

Comments
 (0)