HangfireIO / HangfireIO/Hangfire
This may have occurred because all pooled connections were in use and max pool size was reached.
- Dominant language
- C#
- Stars
- 10.1k
- Forks
- 1.8k
- Avg merge
- 1h 19m
- Merged PRs (30d)
- 1
Description
ERROR Message:
```
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, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
at System.Data.SqlClient.SqlConnection.Open()
at Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection()
at Hangfire.SqlServer.SqlServerStorage.UseConnection[T](DbConnection dedicatedConnection, Func`2 func)
at Hangfire.SqlServer.SqlServerStorage.UseConnection(DbConnection dedicatedConnection, Action`1 action)
at Hangfire.SqlServer.SqlServerConnection.Heartbeat(String serverId)
at Hangfire.Server.ServerHeartbeatProcess.Execute(BackgroundProcessContext context)
```
I have modified the Hangfire source code. The database password will be changed from time to time, so the project needs to dynamically obtain the database password. change code as below:
``` csharp
internal DbConnection CreateAndOpenConnection()
{
using (_options.ImpersonationFunc?.Invoke())
{
DbConnection connection = null;
try
{
connection = new SqlConnection(ConnectionString); //_existingConnection ?? _connectionFactory();
if (connection.State == ConnectionState.Closed)
{
connection.Open();
}
return connection;
}
catch
{
ReleaseConnection(connection);
throw;
}
}
}
```
When adding doWork to a project, this is done every 2 minutes. A connection pooling error occurs after 5 hours. Do not know where is not releasing the connection, please help me
Contributor guide
Research direction
Start with Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection and its UseConnection callers, then trace the Heartbeat path through SqlServerConnection. Reproduce the connection-pool timeout with the reported two-minute workload and inspect whether connections remain in use; done means identifying the leak or lifecycle failure and confirming the pool remains healthy over the same interval.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100