Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The semaphore timeout period has expired" SQL Azure

I am running a .Net MVC Azure Web Site with a SQL Azure database accessed using Entity Framework 6. Intermittently (1 in a thousand or so requests), I get the error "System.ComponentModel.Win32Exception: The semaphore timeout period has expired"

System.Data.SqlClient.SqlException: A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.) ---> System.ComponentModel.Win32Exception: The semaphore timeout period has expired

There seems to be no reason for it and requests before and after the error and their interactions with SQL Azure are fine. Is there any way to handle or resolve this.

like image 642
AlexC Avatar asked Jun 13 '14 13:06

AlexC


People also ask

What does the semaphore timeout period has expired mean?

The "semaphore timeout period has expired" message occurs when your system fails to transfer files from the source drive to the destination drive due to reasons like failure to connect establishment and inability to locate the source or target.

Is not accessible The semaphore timeout period has expired?

Different Situations of the Semaphore Timeout Period has Expired Issue. Solution 1: Use CHKDSK to Check and Repair Bad Sectors & Disk Errors. Solution 2: Run System File Checker to Repair Missing or Corrupted System Files. Solution 3: Temporarily Disable Antivirus and Firewall.

Could not delete partition 0x80070079 The semaphore timeout period has expired?

“The semaphore timeout period has expired” is yet another commonly encountered Windows error. Usually, it is referred to as a backup error and marked with the code 0x80070079. In most of the cases, the problem occurs when the PC/laptop user attempts to backup huge size files or create Windows image backup.


2 Answers

Azure SQL is very different than on premise SQL. When an Azure SQL Server gets overloaded or goes down, it will disconnect a number of connections and when you reconnect you will get sent to another SQL Server.

However with TCP connections you don't know if the other end has terminated the connection unless you actually send information down it, which is why this error occurs.

Once your code know the connection is terminated, it establishes a new connection on the next query, which will work just fine.

With Entity Framework 6 you can now deal with Transient Fault Handling with SQL Azure using Entity Framework

In your DBConfiguration class you need to set your SetExecutionStrategy and configure it. Just create a new class in your project and inherit from DbConfiguration.

public class MyConfiguration : DbConfiguration 
{ 
    public MyConfiguration() 
    { 
        SetExecutionStrategy( 
            "System.Data.SqlClient", 
            () => new SqlAzureExecutionStrategy(1, TimeSpan.FromSeconds(30))); 
    } 
}

Full details at Connection Resiliency / Retry Logic (EF6 onwards)

like image 111
Adam Avatar answered Sep 27 '22 22:09

Adam


There is a know issue where this happens during a VIP swap, and the EF6 retry strategy does not help in this scenario.

https://social.msdn.microsoft.com/Forums/azure/en-US/5e195f94-d4d2-4c2d-8a4e-7d66b4761510/vip-swap-and-the-semaphore-timeout-period-has-expired-errors?forum=ssdsgetstarted&prof=required

like image 44
Co7e Avatar answered Sep 27 '22 23:09

Co7e