Skip to content

Commit

Permalink
fix: Fix error when the node and the client shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
s2quake committed Oct 13, 2024
1 parent fe44d70 commit 1cfdce2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/common/LibplanetConsole.Common/Threading/TaskUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,17 @@ public static async Task<bool> TryDelay(
return false;
}
}

public static async Task<bool> TryWait(Task task)
{
try
{
await task;
return true;
}
catch (Exception)
{
return false;
}
}
}
3 changes: 2 additions & 1 deletion src/console/LibplanetConsole.Console/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using LibplanetConsole.Client.Grpc;
using LibplanetConsole.Common;
using LibplanetConsole.Common.Extensions;
using LibplanetConsole.Common.Threading;
using LibplanetConsole.Console.Grpc;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -215,7 +216,7 @@ public async ValueTask DisposeAsync()
{
await _processCancellationTokenSource.CancelAsync();
_processCancellationTokenSource.Dispose();
await _processTask;
await TaskUtility.TryWait(_processTask);
_processTask = Task.CompletedTask;
_process = null;

Expand Down
3 changes: 2 additions & 1 deletion src/console/LibplanetConsole.Console/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using LibplanetConsole.Blockchain.Grpc;
using LibplanetConsole.Common;
using LibplanetConsole.Common.Extensions;
using LibplanetConsole.Common.Threading;
using LibplanetConsole.Console.Grpc;
using LibplanetConsole.Node;
using LibplanetConsole.Node.Grpc;
Expand Down Expand Up @@ -240,7 +241,7 @@ public async ValueTask DisposeAsync()
{
await _processCancellationTokenSource.CancelAsync();
_processCancellationTokenSource.Dispose();
await _processTask;
await TaskUtility.TryWait(_processTask);
_processTask = Task.CompletedTask;
_process = null;

Expand Down

0 comments on commit 1cfdce2

Please sign in to comment.