Skip to content

Commit f859e60

Browse files
Handle exception on DeleteSession!
If session is not active not invoke DeleteSession!
1 parent e55b471 commit f859e60

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

src/Ydb.Sdk/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- Handle `YdbException` on `DeleteSession`.
2+
- Do not invoke `DeleteSession` if the session is not active.
13
- `YdbException`: Added cancellation token propagation support in `CommitAsync` and `RollbackAsync`.
24
- Deleted legacy exceptions: Driver.TransportException, StatusUnsuccessfulException and InitializationFailureException.
35
- Fixed bug: Unhandled exception System.Net.Http.HttpIOException has now been converted to YdbException ([grpc-dotnet issue](https://github.com/grpc/grpc-dotnet/issues/2638)).

src/Ydb.Sdk/src/Ado/YdbDataReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ private YdbDataReader(
6565

6666
internal static async Task<YdbDataReader> CreateYdbDataReader(
6767
IServerStream<ExecuteQueryResponsePart> resultSetStream,
68-
Action<StatusCode> onStatus,
68+
Action<StatusCode> onNotSuccessStatusCode,
6969
YdbTransaction? ydbTransaction = null,
7070
CancellationToken cancellationToken = default
7171
)
7272
{
73-
var ydbDataReader = new YdbDataReader(resultSetStream, onStatus, ydbTransaction);
73+
var ydbDataReader = new YdbDataReader(resultSetStream, onNotSuccessStatusCode, ydbTransaction);
7474
await ydbDataReader.Init(cancellationToken);
7575

7676
return ydbDataReader;

src/Ydb.Sdk/src/Pool/SessionPool.cs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,6 @@ internal async ValueTask ReleaseSession(TSession session)
149149
{
150150
_idleSessions.Enqueue(session);
151151
}
152-
else
153-
{
154-
_ = DeleteSession(session);
155-
}
156152
}
157153
finally
158154
{
@@ -162,11 +158,20 @@ internal async ValueTask ReleaseSession(TSession session)
162158

163159
private void Release() => _semaphore.Release();
164160

165-
private Task DeleteSession(TSession session) =>
166-
session.DeleteSession().ContinueWith(s =>
161+
private async Task DeleteSession(TSession session)
162+
{
163+
try
167164
{
168-
Logger.LogDebug("Session[{id}] removed with status {status}", session.SessionId, s.Result);
169-
});
165+
if (session.IsActive)
166+
{
167+
await session.DeleteSession();
168+
}
169+
}
170+
catch (YdbException e)
171+
{
172+
Logger.LogError(e, "Failed to delete session");
173+
}
174+
}
170175

171176
public async ValueTask DisposeAsync()
172177
{
@@ -242,7 +247,7 @@ internal TS MakeGrpcRequestSettings<TS>(TS settings) where TS : GrpcRequestSetti
242247
return settings;
243248
}
244249

245-
internal abstract Task<Status> DeleteSession();
250+
internal abstract Task DeleteSession();
246251
}
247252

248253
internal record SessionPoolConfig(

src/Ydb.Sdk/src/Services/Query/SessionPool.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ internal async Task<DescribeTableResult> DescribeTable(string path, DescribeTabl
224224
return response.Operation.Result.Unpack<DescribeTableResult>();
225225
}
226226

227-
internal override async Task<Status> DeleteSession()
227+
internal override async Task DeleteSession()
228228
{
229229
IsActive = false;
230230

@@ -237,6 +237,9 @@ internal override async Task<Status> DeleteSession()
237237
settings
238238
);
239239

240-
return Status.FromProto(deleteSessionResponse.Status, deleteSessionResponse.Issues);
240+
if (deleteSessionResponse.Status.IsNotSuccess())
241+
{
242+
throw YdbException.FromServer(deleteSessionResponse.Status, deleteSessionResponse.Issues);
243+
}
241244
}
242245
}

0 commit comments

Comments
 (0)