We are seeing jobs spontaneously “hang”, which causes all sorts of issues because we use DisableConcurrentExecution quite a bit.
Any idea if this is a configuration issue on our end - or a race condition within hangfire?
Message - New transaction is not allowed because there are other threads running in the session.
Exception type - System.Data.SqlClient.SqlException
10 state change attempt(s) failed due to an exception, moving job to the FailedState
System.Data.SqlClient.SqlException:
at System.Data.SqlClient.SqlConnection.OnError (System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Data.SqlClient.SqlInternalConnection.OnError (System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning (System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Data.SqlClient.TdsParser.TryRun (System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds (System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery (System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery (System.Data.SqlClient, Version=4.6.1.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a)
at Hangfire.SqlServer.SqlCommandBatch.ExecuteNonQuery (Hangfire.SqlServer, Version=1.6.20.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.SqlServer.SqlServerWriteOnlyTransaction.b__7_0 (Hangfire.SqlServer, Version=1.6.20.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.SqlServer.SqlServerStorage+<>c__DisplayClass26_0.b__0 (Hangfire.SqlServer, Version=1.6.20.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.SqlServer.SqlServerStorage+<>c__DisplayClass27_0`1.b__0 (Hangfire.SqlServer, Version=1.6.20.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.SqlServer.SqlServerStorage.UseConnection (Hangfire.SqlServer, Version=1.6.20.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.SqlServer.SqlServerStorage.UseTransaction (Hangfire.SqlServer, Version=1.6.20.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.SqlServer.SqlServerStorage.UseTransaction (Hangfire.SqlServer, Version=1.6.20.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.SqlServer.SqlServerWriteOnlyTransaction.Commit (Hangfire.SqlServer, Version=1.6.20.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.States.BackgroundJobStateChanger.ChangeState (Hangfire.Core, Version=1.7.12.0, Culture=neutral, PublicKeyToken=null)
at Hangfire.Server.Worker.TryChangeState (Hangfire.Core, Version=1.7.12.0, Culture=neutral, PublicKeyToken=null)
.NET Core 3.1
SQL Server Versions (we use both, see error on both)
Microsoft SQL Azure (RTM) - 12.0.2000.8 Oct 1 2020 18:48:35 Copyright (C) 2019 Microsoft Corporation
Microsoft SQL Server 2017 (RTM-CU14-GDR) (KB4494352) - 14.0.3103.1 (X64) Mar 22 2019 22:33:11 Copyright (C) 2017 Microsoft Corporation Enterprise Edition: Core-based Licensing (64-bit) on Windows Server 2016 Datacenter 10.0 (Build 14393: ) (Hypervisor)
I think I have all useful Startup.cs info here:
var options = new SqlServerStorageOptions { SlidingInvisibilityTimeout = TimeSpan.FromSeconds(ApplicationSettings.HangfireSlidingInvisibilityTimeoutSeconds), QueuePollInterval = TimeSpan.FromSeconds(ApplicationSettings.HangfireQueuePollIntervalSeconds) }; GlobalConfiguration.Configuration.UseSqlServerStorage(hangfireConnectionString, options); app.UseHangfireDashboard("/hangfire", new DashboardOptions { Authorization = new[] { new HangfireCustomBasicAuthenticationFilter { User = _configuration.GetSection("HangfireSettings:UserName").Value, Pass = _configuration.GetSection("HangfireSettings:Password").Value } } }); app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 20 });