Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Azure - The timeout period elapsed during the post-login phase

I have azure cloud service - 2 web instances, serving about 500,000 requests per day. Using Azure business database. There is one issue with it - sometimes (avg. once per day, but not in the same time) there is 2-3 minutes long interval while i am unable to query DB, the error message is like this:

System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: Connection Timeout Expired.  The timeout period elapsed during the post-login phase.  The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections.  The duration spent while attempting to connect to this server was - [Pre-Login] initialization=1; handshake=12; [Login] initialization=0; authentication=0; [Post-Login] complete=14004;  ---> System.ComponentModel.Win32Exception: The wait operation timed out
   --- End of inner exception stack trace ---
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(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 System.Data.Entity.Infrastructure.DbExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClassb.<GetResults>b__9()
   at System.Data.Entity.Infrastructure.DbExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.LazyInitValue()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MyProject.MyRepository.GetItems(Boolean includePremium, Int32 a, Int32 b, Int32 c)
   at MyProject.Controllers.MyController.GetItems(String Id, String device)

Numbers in the message - [Pre-Login] initialization=1; handshake=12; [Login] initialization=0; authentication=0; [Post-Login] complete=14004 - are always the same, not some random wait times or something...

Of course I tried to google this error, but all I could find was related to wrong connection management with plain ADO.NET etc. I am using Entity Framework 6, with code-first model, linq to entities queries, queries are not heavy (few ms, always under 1s).

There is this question on SO : Connection timeout in SQL Azure with answer like "this is transient error, just try again" - but this wont solve it for me, I got hundreds of these errors within this interval, I am pretty sure every request fail, so "wait 5 sec and try again" policy wont help here.

Is there something special about Azure DB which I must do about connection lifetime management in EF? Or you think this can be error message for "throttling" DB?

like image 904
rouen Avatar asked Oct 02 '22 19:10

rouen


1 Answers

Well, after some time and some refactoring, it seems this error is indeed indicating throttling. We managed to reduce number of requests per minute, and without any other changes these errors disappeared entirely.

Its a shame that SQL Azure dont give more helpful messages about limits/resources.

like image 135
rouen Avatar answered Oct 12 '22 22:10

rouen