HangfireIO / HangfireIO/Hangfire

Sql Connection Error on Startup Hangs Application

Open
#673 5 comments 0 reactions 0 assignees View on GitHub
a: sql-server t: question
Dominant language
C#
Stars
10.1k
Forks
1.8k
Avg merge
1h 19m
Merged PRs (30d)
1

Description

This issue occurs on startup when using the SqlServer storage package on a web application hosted on IIS. If the Sql Server connection fails for any reason, the Hangfire initialization procedure throws an exception and the application hangs.

Because the exception occurs during startup, the application will remain in this error state until the AppDomain is restarted, which we normally have to do by manually resetting the appPool in IIS.

Here is a stacktrace showing where the exception occurs, taken by temporary disconnecting the instance from the network.

```
[SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +1394
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +1120
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +70
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +910
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +114
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1631
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +117
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +267
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +318
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +211
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +393
System.Data.SqlClient.SqlConnection.Open() +122
Hangfire.SqlServer.SqlServerStorage.CreateAndOpenConnection() +68
Hangfire.SqlServer.SqlServerStorage..ctor(String nameOrConnectionString, SqlServerStorageOptions options) +301
Hangfire.SqlServerStorageExtensions.UseSqlServerStorage(IGlobalConfiguration configuration, String nameOrConnectionString) +86
XXX.Web.Startup.RegisterHangfire(IAppBuilder app) in C:\XXX\Startup.cs:48
XXX.Web.Startup.Configuration(IAppBuilder app) in C:\XXX\Startup.cs:24
```

Statup.cs:

```
Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage(dbConnectionString);
Hangfire.GlobalConfiguration.Configuration.UseAutofacActivator(container, useTaggedLifetimeScope: false);
app.UseHangfireDashboard("/hangfire");
app.UseHangfireServer();
```

Hangfire Versions:
Core 1.5.4.0
SqlServer 1.5.4.0
Windows Server 2012 R2
IIS 8.5

Also it looks like issue may be related:
https://github.com/HangfireIO/Hangfire/issues/273

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.