Open Closed

Application startup hangs when hangfire background jobs exist #3032


User avatar
0
rcalv002 created
  • ABP Framework version: 5.2.1
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace: N/A
  • Steps to reproduce the issue:"

Create a new app-nolayers-pro solution. Add dependies and depends on related modules

    // Hangfire Background worker
    typeof(AbpBackgroundWorkersHangfireModule),

    // Hangfire background jobs
    typeof(AbpBackgroundJobsModule),
    typeof(AbpBackgroundJobsHangfireModule)
    private void ConfigureHangfire(ServiceConfigurationContext context, IConfiguration configuration)
    {
        context.Services.AddHangfire(config =>
        {
            config.UseSqlServerStorage(configuration.GetConnectionString("Default"));
        });
    }
public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
    ..... other confs
    app.UseHangfireDashboard("/hangfire", new DashboardOptions
    {
        AsyncAuthorization = new[] { new AbpHangfireAuthorizationFilter() }
    });
    
    .... also register background workers
    await context.AddBackgroundWorkerAsync<worker1>();
    await context.AddBackgroundWorkerAsync<worker2>();
}

Start up the app. it works. queue some jobs. Your yourproject.hangfire.job table should have stuff in it now

Stop app, next time application attempts startup, it just hangs, no errors. If you DELETE FROM hangfire.job table and start up app, it starts...


7 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi

    Can you share the full steps to reproduce? thanks.

  • User Avatar
    0
    rcalv002 created

    Shared via mail, thanks

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I have checked the project you provided and is works for me.

    I only change the logger configure to write to the console.

  • User Avatar
    0
    rcalv002 created

    Hi Liang,

    Yes the recurring worker jobs are okay, in my sample i triggered queued for processing various non-recurring worker jobs that take TransactionProcessingArgs. You can see in the screenshots above, maybe trigger a bunch of these. You should get failures since you dont have keys to use the domain service and these will end up in retry states. Stop the application and try again? Any time I have jobs in the hangfire.jobs table it wouldnt start back up

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    TransactionProcessingArgs

    Where? I didn't see it in the project you provided. can you provide the steps that I can reproduce?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Here are my steps, there is no problem.

    public class MyArgs
    {
        public string Name { get; set; }
    
        public MyArgs()
        {
            
        }
    }
    
    public class MyJob : AsyncBackgroundJob<MyArgs>, ITransientDependency
    {
        public override async Task ExecuteAsync(MyArgs args)
        {
            await Task.Delay(5000);
            Logger.LogInformation("MyJob..................");
        }
    }
    
    var jobManager= context.ServiceProvider.GetRequiredService<IBackgroundJobManager>();
    
    for (var i = 0; i < 50; i++)
    {
         await jobManager.EnqueueAsync(new MyArgs());
    }
    
  • User Avatar
    0
    rcalv002 created

    The issue turned out to be use of async via AsyncHelper.RunSync in a singleton constructor: my bad.

    Thanks!

Made with ❤️ on ABP v9.1.0-preview. Updated on December 12, 2024, 07:15