File tree Expand file tree Collapse file tree 5 files changed +33
-0
lines changed Expand file tree Collapse file tree 5 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ * Fixed panic on multiple closing driver
2+
13## v3.95.1
24* Added alias from ` ydb.WithFakeTx(ydb.ScriptingQueryMode) ` to ` ydb.WithFakeTx(ydb.QueryExecuteQueryMode) ` for compatibility with legacy code
35
Original file line number Diff line number Diff line change 66 "fmt"
77 "os"
88 "sync"
9+ "sync/atomic"
910
1011 "google.golang.org/grpc"
1112
@@ -103,6 +104,7 @@ type (
103104 children map [uint64 ]* Driver
104105 childrenMtx xsync.Mutex
105106 onClose []func (c * Driver )
107+ closed atomic.Bool
106108
107109 panicCallback func (e interface {})
108110 }
@@ -149,6 +151,11 @@ func (d *Driver) Close(ctx context.Context) (finalErr error) {
149151 defer func () {
150152 onDone (finalErr )
151153 }()
154+
155+ if ! d .closed .CompareAndSwap (false , true ) {
156+ return nil
157+ }
158+
152159 d .ctxCancel ()
153160
154161 d .mtx .Lock ()
Original file line number Diff line number Diff line change @@ -188,6 +188,10 @@ func (c *Client) ExecuteScript(
188188}
189189
190190func (c * Client ) Close (ctx context.Context ) error {
191+ if c == nil {
192+ return xerrors .WithStackTrace (errNilClient )
193+ }
194+
191195 close (c .done )
192196
193197 if err := c .pool .Close (ctx ); err != nil {
Original file line number Diff line number Diff line change 77)
88
99var (
10+ errNilClient = xerrors .Wrap (errors .New ("table client is not initialized" ))
1011 ErrTransactionRollingBack = xerrors .Wrap (errors .New ("ydb: the transaction is rolling back" ))
1112 errWrongNextResultSetIndex = errors .New ("wrong result set index" )
1213 errWrongResultSetIndex = errors .New ("critical violation of the logic - wrong result set index" )
Original file line number Diff line number Diff line change @@ -651,3 +651,22 @@ func TestClusterDiscoveryRetry(t *testing.T) {
651651 }
652652 require .Greater (t , counter , 1 )
653653}
654+
655+ func TestMultipleClosingDriverIssue1585 (t * testing.T ) {
656+ ctx , cancel := context .WithCancel (context .Background ())
657+ defer cancel ()
658+
659+ db , err := ydb .Open (ctx , os .Getenv ("YDB_CONNECTION_STRING" ))
660+ require .NoError (t , err )
661+
662+ require .NotPanics (t , func () {
663+ err = db .Close (ctx )
664+ require .NoError (t , err )
665+
666+ err = db .Close (ctx )
667+ require .NoError (t , err )
668+
669+ err = db .Close (ctx )
670+ require .NoError (t , err )
671+ })
672+ }
You can’t perform that action at this time.
0 commit comments