Base solution for your next web application
Open Closed

Hangfire FOREIGN KEY constraint issue started recently #12690


User avatar
0
OriAssurant created

Hi Team, Our application has been experiencing the following Hangfire error: Microsoft.Data.SqlClient.SqlException (0x80131904): The INSERT statement conflicted with the FOREIGN KEY constraint "FK_HangFire_State_Job". The conflict occurred in database "PortalSystemConfig", table "HangFire.Job", column 'Id'. Prior to September 29, this issue occurred sporadically. However, beginning September 29, the frequency increased significantly, with a large number of Hangfire background-job creation attempts failing. Internal investigation confirmed that the failures were occurring while Hangfire was attempting to create jobs and insert their associated state records. The current leading hypothesis is a race condition in which the corresponding HangFire.Job row is deleted or expired before the HangFire.State insert completes. High job-processing volume and Hangfire cleanup/expiration activity are being investigated as possible contributors; the root cause has not yet been conclusively established. As an immediate mitigation to restore application functionality, we temporarily disabled the FK_HangFire_State_Job foreign key constraint. Following this change, the errors stopped and job processing resumed. This is strictly a temporary mitigation and not the intended permanent solution. We need assistance determining the underlying cause and the appropriate permanent remediation before re-enabling the foreign key constraint. In particular, we would like to understand whether this could be related to Hangfire version/schema behavior, job expiration and cleanup, SQL Server configuration/isolation, or another concurrency issue. The Version of aspnetzero we are running is v13.1.0

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

No answer yet!