Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transport error on delete session #56

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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