Skip to content

Commit

Permalink
bugfix: close UnknownRole connections from a pool
Browse files Browse the repository at this point in the history
We add all connections into ConnectionPool.anyPool, but `MasterRole`
connection only in ConnectionPool.rwPool and `ReplicaRole`
connections only in ConnectionPool.roPool. As a result `UnknownRole`
connections appears only in the `anyPool`. See `setConnectionToPool`
implementation.

So we need to close connections from the `anyPool` instead of
`roPool` + `rwPool`.

Part of #208
  • Loading branch information
oleg-jukovec committed Aug 24, 2022
1 parent eb6b875 commit d7b0e43
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.

- Mode type description in the connection_pool subpackage (#208)
- Missed Role type constants in the connection_pool subpackage (#208)
- ConnectionPool does not close UnknownRole connections (#208)

## [1.8.0] - 2022-08-17

Expand Down
15 changes: 11 additions & 4 deletions connection_pool/connection_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ func (connPool *ConnectionPool) Close() []error {
close(connPool.control)
connPool.state = connClosed

rwErrs := connPool.rwPool.CloseConns()
roErrs := connPool.roPool.CloseConns()
errs := make([]error, 0, len(connPool.addrs))

allErrs := append(rwErrs, roErrs...)
for _, addr := range connPool.addrs {
if conn := connPool.anyPool.DeleteConnByAddr(addr); conn != nil {
if err := conn.Close(); err != nil {
errs = append(errs, err)
}
}
connPool.rwPool.DeleteConnByAddr(addr)
connPool.roPool.DeleteConnByAddr(addr)
}

return allErrs
return errs
}

// GetAddrs gets addresses of connections in pool.
Expand Down
13 changes: 0 additions & 13 deletions connection_pool/round_robin.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@ func (r *RoundRobinStrategy) IsEmpty() bool {
return r.size == 0
}

func (r *RoundRobinStrategy) CloseConns() []error {
r.mutex.Lock()
defer r.mutex.Unlock()

errs := make([]error, len(r.conns))

for i, conn := range r.conns {
errs[i] = conn.Close()
}

return errs
}

func (r *RoundRobinStrategy) GetNextConnection() *tarantool.Connection {
r.mutex.RLock()
defer r.mutex.RUnlock()
Expand Down

0 comments on commit d7b0e43

Please sign in to comment.