@@ -21,7 +21,7 @@ import (
2121// sessionBuilder is the interface that holds logic of creating sessions.
2222type sessionBuilder func (ctx context.Context ) (* Session , error )
2323
24- func New (ctx context.Context , cc grpc.ClientConnInterface , config * config.Config ) * Client {
24+ func New (ctx context.Context , cc grpc.ClientConnInterface , config * config.Config ) * Client { //nolint:funlen
2525 onDone := trace .TableOnInit (config .Trace (), & ctx ,
2626 stack .FunctionID ("github.com/ydb-platform/ydb-go-sdk/v3/internal/table.New" ),
2727 )
@@ -39,6 +39,13 @@ func New(ctx context.Context, cc grpc.ClientConnInterface, config *config.Config
3939 pool.WithIdleTimeToLive [* Session , Session ](config .IdleThreshold ()),
4040 pool.WithCreateItemTimeout [* Session , Session ](config .CreateSessionTimeout ()),
4141 pool.WithCloseItemTimeout [* Session , Session ](config .DeleteTimeout ()),
42+ pool.WithMustDeleteItemFunc [* Session , Session ](func (s * Session , err error ) bool {
43+ if ! s .IsAlive () {
44+ return true
45+ }
46+
47+ return err != nil && xerrors .MustDeleteTableOrQuerySession (err )
48+ }),
4249 pool.WithClock [* Session , Session ](config .Clock ()),
4350 pool.WithCreateItemFunc [* Session , Session ](func (ctx context.Context ) (* Session , error ) {
4451 return newSession (ctx , cc , config )
@@ -210,7 +217,9 @@ func (c *Client) Do(ctx context.Context, op table.Operation, opts ...table.Optio
210217 onDone (attempts , finalErr )
211218 }()
212219
213- err := do (ctx , c .pool , c .config , op , func (err error ) {
220+ err := do (ctx , c .pool , c .config , func (ctx context.Context , s * Session ) error {
221+ return op (ctx , s )
222+ }, func (err error ) {
214223 attempts ++
215224 }, config .RetryOptions ... )
216225 if err != nil {
@@ -239,7 +248,7 @@ func (c *Client) DoTx(ctx context.Context, op table.TxOperation, opts ...table.O
239248 onDone (attempts , finalErr )
240249 }()
241250
242- return retryBackoff (ctx , c .pool , func (ctx context.Context , s table. Session ) (err error ) {
251+ return retryBackoff (ctx , c .pool , func (ctx context.Context , s * Session ) (err error ) {
243252 attempts ++
244253
245254 tx , err := s .BeginTransaction (ctx , config .TxSettings )
@@ -248,9 +257,7 @@ func (c *Client) DoTx(ctx context.Context, op table.TxOperation, opts ...table.O
248257 }
249258
250259 defer func () {
251- if err != nil && ! xerrors .IsOperationError (err ) {
252- _ = tx .Rollback (ctx )
253- }
260+ _ = tx .Rollback (ctx )
254261 }()
255262
256263 if err = executeTxOperation (ctx , c , op , tx ); err != nil {
0 commit comments