HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.32k stars 1.69k forks source link

Hangfire: Cannot insert duplicate key in object 'HangFire.Counter' #1672

Open mkamranaslam opened 4 years ago

mkamranaslam commented 4 years ago

I was using a single deployment/server previously, Now aster shifting to an IIS Cluster with three servers, getting this exception a lot, jobs are not completing.

Violation of PRIMARY KEY constraint 'PK_Counter'. Cannot insert duplicate key in object 'HangFire.Counter'. The duplicate key value is (stats: succeeded).

Using: hangfire 1.7.9

JljHook commented 3 years ago

Hi, We have exact same issue it started after updating to 1.7.19 version. Hangfire is hosted in Azure App Service using 2 instances. Jobs are stuck in the queue due retry logic of 10 times followed by exception: Cannot insert duplicate key row in object 'HangFireProd.Counter' with unique index 'CX_HangFire_Counter'. The duplicate key value is (stats:succeeded).

odinserj commented 3 years ago

CX_HangFire_Counter index shouldn't be unique, so please roll back the changes and make it non-unique back. If you was trying to solve the replication problem on SQL Azure, please use the solution from this thread instead.

https://github.com/HangfireIO/Hangfire/blob/dab0f33d44dccbe7b41196c79d3d4016ab971a7d/src/Hangfire.SqlServer/Install.sql#L565

JljHook commented 3 years ago

We've done this change it works now! We'll do a full schema comparison to get scope what we are missing. Probably we haven't executed migration scripts during version upgrade.