Skip to content

Commit dcb9491

Browse files
committed
bugfix: close UnknownRole connections from a pool
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
1 parent f3d72c7 commit dcb9491

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1616

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

2021
## [1.8.0] - 2022-08-17
2122

connection_pool/connection_pool.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,19 @@ func (connPool *ConnectionPool) Close() []error {
154154
close(connPool.control)
155155
connPool.state = connClosed
156156

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

160-
allErrs := append(rwErrs, roErrs...)
159+
for _, addr := range connPool.addrs {
160+
if conn := connPool.anyPool.DeleteConnByAddr(addr); conn != nil {
161+
if err := conn.Close(); err != nil {
162+
errs = append(errs, err)
163+
}
164+
}
165+
connPool.rwPool.DeleteConnByAddr(addr)
166+
connPool.roPool.DeleteConnByAddr(addr)
167+
}
161168

162-
return allErrs
169+
return errs
163170
}
164171

165172
// GetAddrs gets addresses of connections in pool.

connection_pool/round_robin.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@ func (r *RoundRobinStrategy) IsEmpty() bool {
6060
return r.size == 0
6161
}
6262

63-
func (r *RoundRobinStrategy) CloseConns() []error {
64-
r.mutex.Lock()
65-
defer r.mutex.Unlock()
66-
67-
errs := make([]error, len(r.conns))
68-
69-
for i, conn := range r.conns {
70-
errs[i] = conn.Close()
71-
}
72-
73-
return errs
74-
}
75-
7663
func (r *RoundRobinStrategy) GetNextConnection() *tarantool.Connection {
7764
r.mutex.RLock()
7865
defer r.mutex.RUnlock()

0 commit comments

Comments
 (0)