Error 109: The pipe has been ended while trying to stop service
See original GitHub issueI’m facing a little problem with ending my service. I have an aplication with main loop that is controlled by CancellationTokenSource. This loop is in task that i use to wait.
It looks like that (code is much bigger, so i’ll try to focus on issue):
Service is starting like that:
public Task Run()
{
var token = cancellationTokenSource.Token;
logger.LogInformation("Running dispacher");
return Task.Run(async () => // don't run it on main thread
{
while (true)
{
try
{
token.ThrowIfCancellationRequested();
await Task.Delay(TimeSpan.FromMilliseconds(100), token).ConfigureAwait(false); // application logic simulation
}
catch (TaskCanceledException)
{
break;
}
catch (Exception e)
{
logger.LogError(e, "Exception in dispatcher loop");
}
}
logger.LogInformation("Dispacher shut down");
}, token);
}
Then i keep the reference to this task as mainTask
and in Stop
method i’m doing something like this:
var cts = Container.GetService<CancellationTokenSource>();
cts.Cancel();
mainTask.Wait();
The problem is application is crashing with error Error 109: The pipe has been ended
when i try to stop it as a service. When i’m testing it in console application it is working just fine.
A little debugging showed that crash if happening on line cts.Cancel();
and i’m really stuck in here. There is no exception that i can catch, application just… crashes.
Have you and idea what am i doing wrong?
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (6 by maintainers)
Top GitHub Comments
can you check which release of win10? also, try setting
in the csproj (inside a property group) to get the latest runtime version for self-contained applications. I’ve heard (though only for arm) that there has been some issue where NLog caused uncaught exceptions due to a bug. could you also try to register a handler for
AppDomain.UnhandledException
to log any unhandled exceptions?Setting RuntimeFrameworkVersion worked, now it’s working like a charm! Thanks 😃
I’m not sure why .NET Core isn’t setting latest version of the runtime by default when i’m using latest SDK tools. And i’m baffled why they are not warning about this anywhere in documentation…