Fixed two reliability issues highlighted by SonarCloud (#44)

This commit is contained in:
Peder Holdgaard Pedersen 2025-03-08 20:21:14 +01:00 • committed by GitHub
commit 967d7a4cc8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 4 deletions

View file

@ -169,9 +169,12 @@ public sealed class StdioServerTransport : TransportBase, IServerTransport
{ {
_logger.TransportCleaningUp(EndpointName); _logger.TransportCleaningUp(EndpointName);
_shutdownCts?.Cancel(); if (_shutdownCts != null)
_shutdownCts?.Dispose(); {
_shutdownCts = null; await _shutdownCts.CancelAsync().ConfigureAwait(false);
_shutdownCts.Dispose();
_shutdownCts = null;
}
if (_readTask != null) if (_readTask != null)
{ {

View file

@ -5,6 +5,8 @@ using McpDotNet.Server;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Serilog; using Serilog;
namespace McpDotNet.TestServer;
internal static class Program internal static class Program
{ {
private static ILoggerFactory CreateLoggerFactory() private static ILoggerFactory CreateLoggerFactory()
@ -336,7 +338,7 @@ internal static class Program
Log.Logger.Information("Server started."); Log.Logger.Information("Server started.");
// Run until process is stopped by the client (parent process) // Run until process is stopped by the client (parent process)
while (true) while (true) // NOSONAR
{ {
await Task.Delay(1000); await Task.Delay(1000);
} }

View file

@ -6,6 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyName>TestServer</AssemblyName> <AssemblyName>TestServer</AssemblyName>
<RootNamespace>McpDotNet.TestServer</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>