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 named pipe server hosted service crash #19

Merged
merged 1 commit into from
Jun 18, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,12 @@

while (!stoppingToken.IsCancellationRequested)
{
InitializePipeServer();

_logger.LogInformation("Waiting for client connection...");

try
{
InitializePipeServer();
_logger.LogInformation("Waiting for client connection...");

var waitTask = _server.WaitForConnectionAsync(stoppingToken);

Check warning on line 76 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Dereference of a possibly null reference.

Check warning on line 76 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Dereference of a possibly null reference.

Check warning on line 76 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (arm64)

Dereference of a possibly null reference.

Check warning on line 76 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (arm64)

Dereference of a possibly null reference.
var timeoutTask = Task.Delay(TimeSpan.FromSeconds(10), stoppingToken); // Adjust the timeout as needed

if (await Task.WhenAny(waitTask, timeoutTask) == timeoutTask)
Expand All @@ -99,7 +98,7 @@
}
finally
{
if (_server.IsConnected)

Check warning on line 101 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Dereference of a possibly null reference.

Check warning on line 101 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Dereference of a possibly null reference.

Check warning on line 101 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (arm64)

Dereference of a possibly null reference.

Check warning on line 101 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (arm64)

Dereference of a possibly null reference.
{
_server.Disconnect(); // Ensure the server is disconnected after handling a connection
}
Expand Down Expand Up @@ -139,6 +138,8 @@

if (pipeHandle.IsInvalid)
{
// Access denied errors have been observed here intermittently.
// Throwing here will cause the server to re-initialize in the run loop above.
throw new Win32Exception(Marshal.GetLastWin32Error());
}

Expand Down Expand Up @@ -167,13 +168,13 @@

while (!stoppingToken.IsCancellationRequested && _server.IsConnected)
{
string json = null;

Check warning on line 171 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Converting null literal or possible null value to non-nullable type.

Check warning on line 171 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Converting null literal or possible null value to non-nullable type.

Check warning on line 171 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (arm64)

Converting null literal or possible null value to non-nullable type.

Check warning on line 171 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (arm64)

Converting null literal or possible null value to non-nullable type.

try
{
if (_server.CanRead)
{
json = await reader.ReadLineAsync();

Check warning on line 177 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Converting null literal or possible null value to non-nullable type.

Check warning on line 177 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (x64)

Converting null literal or possible null value to non-nullable type.

Check warning on line 177 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (arm64)

Converting null literal or possible null value to non-nullable type.

Check warning on line 177 in Lanpartyseating.Desktop/Business/NamedPipeServerHostedService.cs

View workflow job for this annotation

GitHub Actions / build (arm64)

Converting null literal or possible null value to non-nullable type.
}
}
catch (IOException ex)
Expand Down
Loading