我有以下内容:-2个web服务器在负载平衡设置中运行。-它们中的每一个都可以使用OwinStartup.cs中的以下代码将重复作业入队:
GlobalConfiguration.Configuration.UseSqlServerStorage("ConnectionString")
.UseFilter(new LogFailureAttribute());
app.UseHangfireServer();
RecurringJob.AddOrUpdate("Job", () =>FunctionTrigger(), Cron.Daily(5, 0));FunctionTrigger是一个简单的函数,使用无状态事务会话将记录插入数据库。
因此,当我使用一个服务器时,作业成功运行,但在负载平衡中发生错误,没有记录插入到数据库中。
这是日志错误:
Hangfire.Server.ServerHeartbeat - Error occurred during execution of 'Server Heartbeat' component. Execution will be retried (attempt 2 of 2147483647) in 00:00:03 seconds.
System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Hangfire.SqlServer.SqlServerStorage.GetConnection()
at Hangfire.Server.ServerHeartbeat.Execute(CancellationToken cancellationToken)
at Hangfire.Server.AutomaticRetryServerComponentWrapper.ExecuteWithAutomaticRetry(CancellationToken cancellationToken)我使用的是Hangfire 1.4.5
**这是因为作业在每台服务器上运行两次吗?!我怎么才能避免这种情况。?!**谢谢。
发布于 2017-07-18 18:54:47
我一直面临着同样的问题,经过一些搜索,我在hangfire discussion上找到了这个讨论,错误发生在Hangfire版本低于1.6.4的时候。该问题已在1.6.4 release上修复。如果你仍然有这个问题,希望这能对你有所帮助。
https://stackoverflow.com/questions/39346952
复制相似问题