@@ -2,6 +2,7 @@ package conn
22
33import (
44 "context"
5+ "github.com/ydb-platform/ydb-go-sdk/v3/internal/closer"
56 "sync"
67 "sync/atomic"
78 "time"
@@ -52,6 +53,10 @@ type pool struct {
5253
5354func (p * pool ) Pessimize (ctx context.Context , cc Conn , cause error ) {
5455 e := cc .Endpoint ().Copy ()
56+
57+ p .mtx .RLock ()
58+ defer p .mtx .RUnlock ()
59+
5560 cc , ok := p .conns [e .Address ()]
5661 if ! ok {
5762 return
@@ -78,11 +83,15 @@ func (p *pool) Release(ctx context.Context) error {
7883
7984 close (p .done )
8085
81- p .mtx .Lock ()
82- defer p .mtx .Unlock ()
86+ p .mtx .RLock ()
87+ conns := make ([]closer.Closer , 0 , len (p .conns ))
88+ for _ , c := range p .conns {
89+ conns = append (conns , c )
90+ }
91+ p .mtx .RUnlock ()
8392
8493 var issues []error
85- for _ , c := range p . conns {
94+ for _ , c := range conns {
8695 if err := c .Close (ctx ); err != nil {
8796 issues = append (issues , err )
8897 }
@@ -105,7 +114,8 @@ func (p *pool) GetConn(e endpoint.Endpoint) Conn {
105114 e ,
106115 p .config ,
107116 withOnClose (func (c * conn ) {
108- // conn.Conn.Close() must called on under locked p.mtx
117+ p .mtx .Lock ()
118+ defer p .mtx .Unlock ()
109119 delete (p .conns , c .Endpoint ().Address ())
110120 }),
111121 )
0 commit comments