Persistent Servers even after Truncating/removing Hangfire tables from Database

Tags: #<Tag:0x00007f185dabd200> #<Tag:0x00007f185dabd138>

Hello,
I’ve been trying to figure out what’s happening with my Hangfire setup for the past week, but to no avail. Basically, I am not able get rid of servers and queues that should not be there. I’m using Hangfire.AspNetCor and Hangfire.SqlServer versions 1.7.25 in an ASP.NET Core 2.2 environment. Here’s what I have in my ConfigureServices:

    services.AddHangfire(configuration => configuration
        .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
        .UseSimpleAssemblyNameTypeSerializer()
        .UseRecommendedSerializerSettings()
        .UseSqlServerStorage(Configuration.GetConnectionString("DB"), new SqlServerStorageOptions
        {

            CommandBatchMaxTimeout = TimeSpan.FromMinutes(5),
            SlidingInvisibilityTimeout = TimeSpan.FromMinutes(5),
            QueuePollInterval = TimeSpan.Zero,
            UseRecommendedIsolationLevel = true,
            DisableGlobalLocks = true
        }));

    services.AddHangfireServer();

I schedule my background job when a user clicks on a button inside a controller and I give it a timespan of 0 to make the job execute immediately (I’ve also tried Enqueue instead of Schedule):
BackgrounJobs.Schedule(() => runMyCode(), TimeSpan.FromSeconds(0));

In a previous version of my code I had assigned my “runMyCode” routine to a specific queue called “projects” by using the attribute [Queue(“projects”)]. Later I removed this attribute and opted for Hangfire to just use the “default” queue. However, now every time I run my application and view the “servers” in the dashboard I see that there is still a server that has the “projects” queue assigned to it, and no matter what I do when I execute my code it seems to run a older version of my code on that server and in that queue. However, even thought a new server with the default queue is also created, it’s never used.

I have tried truncating all the Hangfire tables in my SQL Server database, I’ve even Dropped all the tables and let Hangfire re-add them. But the “extra” server(s) keep coming back. I’ve even removed the Hangfire package from my dependencies in my application and re-added it, but nothing has changed.

Why is Hangfire running an old version of my code? How can I get rid of the extra server and queues permanently? I have no idea what I’m doing wrong. I’d really appreciate any help. Thanks!

Hi,

did you find a solution?
iam fighting with the same problem… i even deleted all server on shutdown

  IMonitoringApi monitoringApi = JobStorage.Current.GetMonitoringApi();
            foreach (var s in monitoringApi.Servers())
            {
                JobStorage.Current.GetConnection().RemoveServer(s.Name);
            }

but if i start my project and enqueue a job it always uses an old code state. I deleted my whole database too but nothing working…

Hi Marc,
Unfortunately, no I haven’t found a solution. I’m still struggling with it, and no one has replied to this post. I did exactly what you described as well, but every time I run the code the same servers keep coming back, and I have no clue where they’re coming from. I even removed any references to Hangfire from my code, and then re added it to no avail. We can’t be the only people who are experiencing this issue. There has to be a solution, right? Otherwise, this product is frustratingly useless.

yeah at the moment iam investing much more time in it than i wanted… i was able to solve it temporarly now… deleted database and since i was running my stuff on docker i deleted all docker images/container too…

i had another instance of hangfire on docker running and stopped this too…

now it is running my new code but i need to analyse which of my steps was the solution and what is the exact source of the problem… and i am not sure if this solved my prob permanently