Search code examples
hangfire

Hangfire 1.3.4 - deleted jobs stuck in queue


We are running hangfire single threaded using BackgroundJobServerOptions.WorkerCount = 1 (because we have a requiement for ordered processing).

Most of the time this is no problem, but occasionally a job gets stuck for entirely expected reasons (eg, the actual code it is running goes into an infintite loop), but because we are running single threaded this prevents other jobs in the queue from starting.

In order to try and work around this, we delete the job, but then it stays on the queue, blocking any other job from starting:

enter image description here

The only way I have found to resolve this is to drop and recreate the hangfire DB which is obviously not great.

Why does deleting a running job in hangfire not also remove it from the queue? Is this weird delete behavior a bug which to be fixed in a later version, or is this behavior by design because we're running single threaded?

If this is by design then how do you cancel a processing job in a way which removes it from the queue?


Solution

  • Well it seems that this behavior is by design.

    If the IIS app pool worker is recycled, Hangfire will start processing the next task immediately. However, without this restart Hangfire will "hang" indefinitely.

    An issue was raised on github about this, however it has not been solved yet: https://github.com/HangfireIO/Hangfire/issues/80

    With no way to cancel or manually "fail" a job, this makes hangfire a lot less useful in a single threaded scenario.

    Update: this has been partially or fully addressed in some later version of Hangfire.