44 "context"
55
66 "github.com/ydb-platform/ydb-go-genproto/Ydb_Query_V1"
7+ "github.com/ydb-platform/ydb-go-genproto/protos/Ydb"
78 "github.com/ydb-platform/ydb-go-genproto/protos/Ydb_Query"
89
910 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
@@ -80,6 +81,10 @@ func (tx transaction) Execute(ctx context.Context, q string, opts ...options.TxE
8081
8182 _ , res , err := execute (ctx , tx .s , tx .s .grpcClient , q , options .TxExecuteSettings (tx .ID (), opts ... ).ExecuteSettings )
8283 if err != nil {
84+ if xerrors .IsOperationError (err ) {
85+ tx .s .setStatus (statusClosed )
86+ }
87+
8388 return nil , xerrors .WithStackTrace (err )
8489 }
8590
@@ -98,8 +103,17 @@ func commitTx(ctx context.Context, client Ydb_Query_V1.QueryServiceClient, sessi
98103 return nil
99104}
100105
101- func (tx transaction ) CommitTx (ctx context.Context ) (err error ) {
102- return commitTx (ctx , tx .s .grpcClient , tx .s .id , tx .ID ())
106+ func (tx transaction ) CommitTx (ctx context.Context ) error {
107+ err := commitTx (ctx , tx .s .grpcClient , tx .s .id , tx .ID ())
108+ if err != nil {
109+ if xerrors .IsOperationError (err , Ydb .StatusIds_BAD_SESSION ) {
110+ tx .s .setStatus (statusClosed )
111+ }
112+
113+ return xerrors .WithStackTrace (err )
114+ }
115+
116+ return nil
103117}
104118
105119func rollback (ctx context.Context , client Ydb_Query_V1.QueryServiceClient , sessionID , txID string ) error {
@@ -114,6 +128,15 @@ func rollback(ctx context.Context, client Ydb_Query_V1.QueryServiceClient, sessi
114128 return nil
115129}
116130
117- func (tx transaction ) Rollback (ctx context.Context ) (err error ) {
118- return rollback (ctx , tx .s .grpcClient , tx .s .id , tx .ID ())
131+ func (tx transaction ) Rollback (ctx context.Context ) error {
132+ err := rollback (ctx , tx .s .grpcClient , tx .s .id , tx .ID ())
133+ if err != nil {
134+ if xerrors .IsOperationError (err , Ydb .StatusIds_BAD_SESSION ) {
135+ tx .s .setStatus (statusClosed )
136+ }
137+
138+ return xerrors .WithStackTrace (err )
139+ }
140+
141+ return nil
119142}
0 commit comments