Skip to content

Commit baf2df9

Browse files
Copilotasmyasnikov
andcommitted
fix: sessions not removed from pool on context errors (SESSION_BUSY bug)
Co-authored-by: asmyasnikov <14202262+asmyasnikov@users.noreply.github.com>
1 parent 50cae94 commit baf2df9

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

internal/xerrors/session.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ import (
66
)
77

88
func MustDeleteTableOrQuerySession(err error) bool {
9+
// Context errors (context.Canceled, context.DeadlineExceeded) indicate that a
10+
// query may still be running on the server side. The session must be invalidated
11+
// to prevent SESSION_BUSY errors on subsequent requests.
12+
if IsContextError(err) {
13+
return true
14+
}
15+
916
if IsOperationError(err,
1017
Ydb.StatusIds_BAD_SESSION,
1118
Ydb.StatusIds_SESSION_BUSY,

internal/xerrors/session_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
func TestMustDeleteTableOrQuerySession(t *testing.T) {
1818
t.Run("True", func(t *testing.T) {
1919
for _, err := range []error{
20+
context.Canceled,
21+
context.DeadlineExceeded,
2022
Transport(
2123
//nolint:staticcheck
2224
// ignore SA1019
@@ -63,8 +65,6 @@ func TestMustDeleteTableOrQuerySession(t *testing.T) {
6365
t.Run("False", func(t *testing.T) {
6466
for _, err := range []error{
6567
fmt.Errorf("unknown error"), // retryer given unknown error - we will not operationStatus and will close session
66-
context.DeadlineExceeded,
67-
context.Canceled,
6868
Transport(grpcStatus.Error(grpcCodes.ResourceExhausted, "")),
6969
Transport(grpcStatus.Error(grpcCodes.OutOfRange, "")),
7070
Operation(

0 commit comments

Comments
 (0)