Skip to content

Commit

Permalink
Fix transport error on delete session (#56)
Browse files Browse the repository at this point in the history
Fix transport error on delete session
  • Loading branch information
XmasApple authored Nov 21, 2023
1 parent 84b25c7 commit e5dec2e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- Fix timeout error on create session
- Fix transport error on delete session

## v0.1.4
- Add exception throwing when results truncated
- lint: add line feed at file end
Expand Down
3 changes: 1 addition & 2 deletions src/Ydb.Sdk/src/Services/Table/CreateSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ public async Task<CreateSessionResponse> CreateSession(CreateSessionSettings? se
request: request,
settings: settings);

CreateSessionResult? resultProto;
var status = UnpackOperation(response.Data.Operation, out resultProto);
var status = UnpackOperation(response.Data.Operation, out CreateSessionResult? resultProto);

CreateSessionResponse.ResultData? result = null;
if (status.IsSuccess && resultProto != null)
Expand Down
3 changes: 2 additions & 1 deletion src/Ydb.Sdk/src/Services/Table/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ protected virtual void Dispose(bool disposing)
_logger.LogTrace($"Closing detached session on dispose: {Id}");

var client = new TableClient(Driver, new NoPool());
_ = client.DeleteSession(Id, new DeleteSessionSettings
var task = client.DeleteSession(Id, new DeleteSessionSettings
{
TransportTimeout = DeleteSessionTimeout
});
task.Wait();
}
else
{
Expand Down
13 changes: 8 additions & 5 deletions src/Ydb.Sdk/src/Services/Table/SessionPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public async Task<GetSessionResponse> GetSession()
{
var sessionId = _idleSessions.Pop();

SessionState? sessionState;
if (!_sessions.TryGetValue(sessionId, out sessionState))
if (!_sessions.TryGetValue(sessionId, out var sessionState))
{
continue;
}
Expand Down Expand Up @@ -152,8 +151,7 @@ internal void ReturnSession(string id)
{
lock (_lock)
{
SessionState? oldSession;
if (_sessions.TryGetValue(id, out oldSession))
if (_sessions.TryGetValue(id, out var oldSession))
{
var session = new Session(
driver: _driver,
Expand Down Expand Up @@ -275,15 +273,20 @@ private void Dispose(bool disposing)

if (disposing)
{
var tasks = new Task[_sessions.Count];
var i = 0;
foreach (var state in _sessions.Values)
{
_logger.LogTrace($"Closing session on session pool dispose: {state.Session.Id}");

_ = _client.DeleteSession(state.Session.Id, new DeleteSessionSettings
var task = _client.DeleteSession(state.Session.Id, new DeleteSessionSettings
{
TransportTimeout = Session.DeleteSessionTimeout
});
tasks[i++] = task;
}

Task.WaitAll(tasks);
}

_disposed = true;
Expand Down

0 comments on commit e5dec2e

Please sign in to comment.