Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Stack overflow in worker service if ExecuteAsync throws an exception #130

Closed
TETYYS opened this issue Feb 9, 2020 · 3 comments
Closed

Comments

@TETYYS
Copy link

TETYYS commented Feb 9, 2020

To reproduce:

Create a new worker service - dotnet new worker
Install Singularity.Microsoft.DependencyInjection (v0.17.1)
Worker.cs -

using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;

namespace test
{
    public class Worker : BackgroundService
    {

        public Worker(IServiceProvider Provider)
        {
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            throw new Exception("a");
        }
    }
}

Program.cs -

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Singularity;

namespace test
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .UseServiceProviderFactory(new SingularityServiceProviderFactory(SingularitySettings.Microsoft))
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddHostedService<Worker>();
                });
    }
}

Workaround - don't throw exceptions in ExecuteAsync

@Barsonax
Copy link
Owner

Strange doesn't immediately looks like its related to Singularity.

Will have to check it later.

@Barsonax
Copy link
Owner

Barsonax commented Feb 16, 2020

Reproduced and probably found the fix already. Prerelease package should be out shortly for further testing.

@Barsonax
Copy link
Owner

Fixed in 0.17.2, thanks for reporting @TETYYS

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants