Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upSqlClient's connection resiliency adds 10 seconds to database existence checks. Consider exposing a way to override it at runtime #14644
Comments
karelz
added
the
area-System.Data.SqlClient
label
Dec 20, 2016
divega
referenced this issue
Dec 23, 2016
Open
Perf problem on existence checks caused by SqlClient's connection resiliency feature #7283
divega
referenced this issue
Jan 20, 2017
Open
ConnectRetryCount causes 10 second hangs on common EF tasks #148
stephentoub
added this to the Future milestone
Apr 12, 2017
divega
changed the title
SqlClient's connection resiliency causes performance issues to EF customers. Consider exposing a way to override it at runtime
SqlClient's connection resiliency hinders fail-fast health or database existence checks. Consider exposing a way to override it at runtime
Jul 31, 2018
divega
changed the title
SqlClient's connection resiliency hinders fail-fast health or database existence checks. Consider exposing a way to override it at runtime
SqlClient's connection resiliency adds 10 seconds to database existence checks. Consider exposing a way to override it at runtime
Oct 13, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
divega commentedDec 20, 2016
•
edited
This is to follow up on a specific issue a customer created today on EF Core at aspnet/EntityFrameworkCore#7283, but the problem has been brought to our attention before.
Both EF6 and EF Core provide APIs that allow applications to create and initialize databases, check for their existence and modify their schemas. These operations can happen at design time (e.g. when using the migrations feature) or at runtime. Attempting to connect to a database that doesn't exist is part of the normal flow of these operations.
In .NET Framework 4.5.1 SqlClient introduced a connection resiliency feature that performs automatic retries if failures occur during
SqlConnection.Open()
. Two new settingsConnectRetryCount
andConnectRetryInterval
were added to the list of settings recognized in connection strings and a default behavior was adopted so if the first attempt to connect to a database fails a retry will occur after 10 seconds if these settings are not specified. The same feature is now included in the .NET Core version of SqlClient.With only the default behavior this feature introduces a lag of 10 second for any calling code that attempts to connect to a database that doesn't exist. It also prevents any calling code from implementing its own (potentially more efficient) retry logic correctly. This severely affects customer experience and can potentially affect runtime performance.
Two main approaches have been proposed to mitigate this issue on EF code, but they have severe disadvantages:
ConnectRetryCount=0
when working EF and make sure the feature is disabled any time EF runtime or tooling creates a connection string, or even throw if an attempt is made to use a connection that has the feature enabled. The main disadvantages of this approach are:ConnectRetryCount = 0
and create a separateSqlConnection
object to perform existence checks.SqlConnection
object to be used in the EF context. It is possible that the password would have already been removed from theConnectionString
in that connection object if it was open before, so in that case the connection string would not contain enough credentials to be able to create a separate functional connection object.At this point we believe that if
SqlConnection
exposed a way to programmatically disable connection retries without requiring the modification of the connection string we could modify EF6 and EF Core code to restore the correct behavior and eliminate 10 second lags. We are happy to discuss other options with the SqlClient team.Also note that this issue applies to both .NET Core and .NET Framework.
cc @ajcvickers
Note on how EF Core implements its own retry logic to check for database existence:
In general, any code that is calling
SqlConnection.Open()
can leverage contextual knowledge to make connection retries more efficient. E.g.: