Skip to content

Commit 8f9694e

Browse files
committed
bugfix: close unknown connections from a pool
We add all connections into ConnectionPool.anyPool, but `master` connection only in ConnectionPool.rwPool and `replica` connections only in ConnectionPool.roPool. As a result `unknown` connections appears only in the `anyPool`. See `setConnectionToPool` implementation. So we need to close connections from the `anyPool` instead of `roPool` + `rwPool`.
1 parent b1fbdd3 commit 8f9694e

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

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)