question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error 109: The pipe has been ended while trying to stop service

See original GitHub issue

I’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:closed
  • Created 6 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
dasMullicommented, Mar 14, 2018

can you check which release of win10? also, try setting

<RuntimeFrameworkVersion>2.0.6</RuntimeFrameworkVersion>

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?

0reactions
jakosscommented, Mar 14, 2018

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…

Read more comments on GitHub >

github_iconTop Results From Across the Web

System error 109: The pipe has ended [Quick Fix]
The System error 109: The pipe has ended usually occurs due to a faulty device driver or malware infection. Perform a full system...
Read more >
System error 109: ERROR_BROKEN_PIPE on Windows 10
The System error 109: The pipe has ended message occurs when using your computer or launching a specific application. ERROR_BROKEN_PIPE can ...
Read more >
How to Fix The pipe has been ended error 109 in Windows 10
This error indicates that there is something wrong in your Windows computer or in software installed in computer that is triggering the error....
Read more >
How to fix System error 109: ERROR_BROKEN_PIPE on ...
Solution 1. Scan your PC from malware · Solution 2. Roll back system drivers · Solution 3. Update Google Chrome · Solution 4....
Read more >
How to fix Error 109 (ERROR_BROKEN_PIPE) - The pipe has ...
This article features error number Code 109, commonly known as ERROR_BROKEN_PIPE and it is described as The pipe has been ended.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found