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
89 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/options"
910 "github.com/ydb-platform/ydb-go-sdk/v3/internal/query/result"
@@ -38,6 +39,8 @@ func (s *Session) QueryResultSet(
3839
3940 r , err := execute (ctx , s .ID (), s .client , q , options .ExecuteSettings (opts ... ), withTrace (s .trace ))
4041 if err != nil {
42+ s .handleSessionErrorStatus (err )
43+
4144 return nil , xerrors .WithStackTrace (err )
4245 }
4346
@@ -54,6 +57,8 @@ func (s *Session) queryRow(
5457) (row query.Row , finalErr error ) {
5558 r , err := execute (ctx , s .ID (), s .client , q , settings , resultOpts ... )
5659 if err != nil {
60+ s .handleSessionErrorStatus (err )
61+
5762 return nil , xerrors .WithStackTrace (err )
5863 }
5964
@@ -120,6 +125,8 @@ func (s *Session) Begin(
120125
121126 txID , err := begin (ctx , s .client , s .ID (), txSettings )
122127 if err != nil {
128+ s .handleSessionErrorStatus (err )
129+
123130 return nil , xerrors .WithStackTrace (err )
124131 }
125132
@@ -140,6 +147,8 @@ func (s *Session) Exec(
140147
141148 r , err := execute (ctx , s .ID (), s .client , q , options .ExecuteSettings (opts ... ), withTrace (s .trace ))
142149 if err != nil {
150+ s .handleSessionErrorStatus (err )
151+
143152 return xerrors .WithStackTrace (err )
144153 }
145154
@@ -162,8 +171,19 @@ func (s *Session) Query(
162171
163172 r , err := execute (ctx , s .ID (), s .client , q , options .ExecuteSettings (opts ... ), withTrace (s .trace ))
164173 if err != nil {
174+ s .handleSessionErrorStatus (err )
175+
165176 return nil , xerrors .WithStackTrace (err )
166177 }
167178
168179 return r , nil
169180}
181+
182+ func (s * Session ) handleSessionErrorStatus (err error ) {
183+ switch {
184+ case xerrors .IsTransportError (err ) || xerrors .IsOperationError (err , Ydb .StatusIds_SESSION_BUSY , Ydb .StatusIds_BAD_SESSION ):
185+ s .SetStatus (session .StatusError )
186+ case xerrors .IsOperationError (err , Ydb .StatusIds_BAD_SESSION ):
187+ s .SetStatus (session .StatusClosed )
188+ }
189+ }
0 commit comments