You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Concurrency level greater than connection pool size (in our case minimum 200)
There is some network latency between the client and the server (for example SQL server MI running in Azure)
There is conn.StateChange event handler that executes some sql command when connection state is open
The exact exception is:
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.
This happens in both dotnet6 and dotnet7 runtimes, with any version of Microsoft.Data.SqlClient or System.Data.SqlClient packages
After a small period of time all 100 connections maintained by the pool are blocked indefinitely, and all subsequent sql connections time out on connection open. Everything remains blocked.
To reproduce
// See https://aka.ms/new-console-template for more informationusingMicrosoft.Data.SqlClient;conststringConnectionString="Server=YOUR_SERVER;Database=YOUR_DB;User Id=YOUR_USER;Password=YOUR_PASS;MultipleActiveResultSets=true";awaitExecuteConcurrentCommands();Console.WriteLine("FINISHED");Console.ReadLine();asyncTaskExecuteConcurrentCommands(){vartasks=Enumerable.Range(0,1000).Select(ExecuteCommand);awaitTask.WhenAll(tasks);}asyncTaskExecuteCommand(intindex){usingvarconn=newSqlConnection(ConnectionString);conn.StateChange+=void(sender,evt)=>{if(evt.CurrentState==System.Data.ConnectionState.Open){varsenderConnection=(SqlConnection)sender;varcommandText="SET TEXTSIZE "+index;using(varcommand=senderConnection.CreateCommand()){command.CommandText=commandText;command.ExecuteNonQuery();}}};try{awaitconn.OpenAsync();usingvarcommand=conn.CreateCommand();command.CommandText=$"SELECT TOP 1 {index} from [__DocumentSignerMigration]";varresult=awaitcommand.ExecuteScalarAsync();Console.WriteLine($"Executed select command {index}, result: "+result);}catch(Exceptionex){Console.WriteLine("CAUGHT EXCEPTION, "+ex);}finally{awaitconn.CloseAsync();}}
Further technical details
Microsoft.Data.SqlClient version: 4.0.0
.NET target: dotnet7
SQL Server version: Azure Sql Server MI
Operating system: Debian 11
The text was updated successfully, but these errors were encountered:
Yes it is simillar to #422 but in our case there is one more thing, all connections maintained by the pool remain blocked, all 100 connections. Indefinitely. The only thing we can do in this case is to restart the process.
The workaraounds in our case, were to either remove MARS were possible, and in other cases wehere MARS rtequired, we have removed the event handler, and executed the "SET TEXTSIZE" cmd after the connection opened, without the event handler.
Describe the bug
Connection timeout exceptions when all are met:
The exact exception is:
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.
This happens in both dotnet6 and dotnet7 runtimes, with any version of Microsoft.Data.SqlClient or System.Data.SqlClient packages
After a small period of time all 100 connections maintained by the pool are blocked indefinitely, and all subsequent sql connections time out on connection open. Everything remains blocked.
To reproduce
Further technical details
Microsoft.Data.SqlClient version: 4.0.0
.NET target: dotnet7
SQL Server version: Azure Sql Server MI
Operating system: Debian 11
The text was updated successfully, but these errors were encountered: