Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix connection leak of session with dropped keyspace #130

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 nil, 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 nil, ProtocolNotSupported
err = ProtocolNotSupported
return
}

if len(p.config.Keyspace) != 0 {
err = conn.SetKeyspace(ctx, p.config.Version, p.config.Keyspace)
if err != nil {
return nil, 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