【问题标题】:Error occurred during execution of ‘Server Heartbeat’-Load Balance执行“服务器心跳”-负载均衡时出错
【发布时间】:2017-01-13 18:57:43
【问题描述】:

我有以下内容: - 在负载平衡设置中运行的 2 个 Web 服务器。 - 其中每一个都可以在 OwinStartup.cs 中使用以下代码将 Recurring Jobs 排入队列:

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

**这是因为作业在每台服务器上运行两次吗?!我怎样才能避免这种情况。 ?! ** 谢谢。

【问题讨论】:

  • 对以上内容有意见吗?

标签: sql-server asp.net-mvc scheduled-tasks recurring hangfire


【解决方案1】:

我也遇到过同样的问题,经过一番搜索,我在hangfire discussion 上找到了这个讨论,Hangfire 版本 release 上得到修复。 如果您仍然遇到问题,希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2013-08-26
    • 1970-01-01
    • 2017-06-12
    • 2019-01-05
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 2021-03-17
    • 2021-01-10
    相关资源
    最近更新 更多