Skip to main content Explore View all products (200+) Microsoft Foundry Azure Copilot GitHub Copilot Azure Kubernetes Service (AKS) Azure Cosmos DB Azure Database for PostgreSQL Azure Arc Microsoft Fabric Linux virtual machines in Azure Foundry Models Foundry Agent Service Foundry IQ Foundry Tools Foundry Control Plane Observability in Foundry Control Plane Azure OpenAI in Foundry Models Azure Speech in Foundry Tools Azure Machine Learning View all databases Azure Cosmos DB Azure DocumentDB Azure SQL Azure Database for PostgreSQL Azure Managed Redis Microsoft Fabric Azure Databricks Linux virtual machines in Azure Windows Server on Azure Azure Functions Azure Virtual Machine Scale Sets Azure API Management Azure Container Apps Azure Kubernetes Service (AKS) Azure Kubernetes Fleet Manager Azure Container Registry Azure Red Hat OpenShift Azure Container Instances Azure Container Storage Azure Arc Azure Local Microsoft Defender for Cloud Azure Monitor Microsoft Sentinel Azure Migrate View all solutions (40+) Cloud solutions for small and medium businesses Cloud migration and modernization center Data analytics for AI Azure Databases AI apps and agents Microsoft Marketplace Microsoft Sovereign Cloud AI apps and agents Responsible AI with Azure AI Infrastructure Data analytics for AI Machine learning operations (MLOps) Low-code application development on Azure Integration Services Serverless computing DevOps Migration and modernization center .NET apps migration Databases on Azure Linux on Azure Oracle on Azure SAP on the Microsoft Cloud Adaptive cloud High-performance computing (HPC) Infrastructure as a service (IaaS) Resiliency Azure Essentials Frontier Accelerate for Azure FinOps on Azure Microsoft Marketplace Azure pricing overview Create an Azure account Free Azure services Flexible purchase options Pricing calculator FinOps on Azure Maximize ROI from AI Azure savings plans Azure reservations Azure Hybrid Benefit Virtual Machines Azure SQL Microsoft Foundry Microsoft Fabric Azure Kubernetes Service (AKS) Microsoft Defender for Cloud View more Software Development Companies Microsoft Marketplace Find a partner Resources for Azure partners Get started with Azure Customer stories Analyst reports, white papers, and e-books Videos Learn more about cloud computing Documentation Explore Azure portal Developer resources Quickstart templates Resources for startups Developer community Students Azure for partners Blog Events and Webinars Learn Support Contact Sales Get started with Azure Sign in

We are happy to announce that Azure Load Balancer now supports configurable TCP Idle timeout for your Cloud Services and Virtual Machines. This feature can be configured using the Service Management API, PowerShell or the service model

Overview

In its default configuration, Azure Load Balancer has an ‘idle timeout’ setting of 4 minutes.

This means that if you have a period of inactivity on your tcp or http sessions for more than the timeout value, there is no guarantee to have the connection maintained between the client and your service.

When the connection is closed, your client application will get an error message like “The underlying connection was closed: A connection that was expected to be kept alive was closed by the server”.

A common practice to keep the connection active for a longer period is to use TCP Keep-alive (You can find .NET examples here). Packets are sent when no activity is detected on the connection. By keeping on-going network activity, the idle timeout value is never hit and the connection is maintained for a long period.

While TCP Keep-alive works well for scenarios where battery is not a constraint, it is generally not a valid option for mobile applications. Using TCP Keep-alive from a mobile application will likely drain the device battery faster.

To support such scenarios, we have added support for a configurable idle timeout. You can now set it for a duration between 4 and 30 minutes. This setting works for inbound connections only.

diagram

Scenarios

Configure TCP timeout to an endpoint on a Virtual Machine via PowerShell or Service Management API

Configure TCP timeout for your Load-Balanced Endpoint Sets via PowerShell or Service Management API.

Configure TCP timeout for your Instance-Level Public IP

Configure TCP timeout for your Web/Worker roles via the service model.

PowerShell examples

Make sure to Download and install the latest Azure PowerShell

Configure TCP timeout for your Instance-Level Public IP to 15 minutes.

Set-AzurePublicIP –PublicIPName webip –VM MyVM -IdleTimeoutInMinutes 15

IdleTimeoutInMinutes is optional. If not set, the default timeout is 4 minutes. Its value can now be set between 4 and 30 minutes.

Set Idle Timeout when creating an Azure endpoint on a Virtual Machine

Get-AzureVM -ServiceName "mySvc" -Name "MyVM1" | Add-AzureEndpoint -Name "HttpIn" -Protocol "tcp" -PublicPort 80 -LocalPort 8080 -IdleTimeoutInMinutes 15| Update-AzureVM

Retrieve your idle timeout configuration

PS C:\> Get-AzureVM –ServiceName “MyService” –Name “MyVM” | Get-AzureEndpoint
 
VERBOSE: 6:43:50 PM - Completed Operation: Get Deployment
 
LBSetName : MyLoadBalancedSet
 
LocalPort : 80
 
Name : HTTP
 
Port : 80
 
Protocol : tcp
 
Vip : 65.52.xxx.xxx
 
ProbePath :
 
ProbePort : 80
 
ProbeProtocol : tcp
 
ProbeIntervalInSeconds : 15
 
ProbeTimeoutInSeconds : 31
 
EnableDirectServerReturn : False
 
Acl : {}
 
InternalLoadBalancerName :
 
IdleTimeoutInMinutes : 15

Set the TCP timeout on a load balanced endpoint set

If endpoints are part of a load balanced endpoint set, the TCP timeout must be set on the load balanced endpoint set

Set-AzureLoadBalancedEndpoint -ServiceName "MyService" -LBSetName "LBSet1" -Protocol tcp -LocalPort 80 -ProbeProtocolTCP -ProbePort 8080 -IdleTimeoutInMinutes 15

Cloud Service example

You can leverage the Azure SDK for .NET 2.4 to update your Cloud Service

Endpoint settings for Cloud Services are made in the .csdef. So, in order to update the TCP timeout for a Cloud Services deployment, a deployment upgrade is required. An exception is if the TCP timeout is only specified for a Public IP. Public IP settings are in the .cscfg, and they can be updated through deployment update and upgrade.

The .csdef changes for endpoint settings are:


  
    
  
The .cscfg changes for the timeout setting on Public IPs are:
 

  
  
    
      
        
      
    
  


API example

You can configure the TCP idle timeout using the service management API

Make sure to add the x-ms-version header  is set to version 2014-06-01 or higher.

Update the configuration of the specified load-balanced input endpoints on all Virtual Machines in a deployment

Request

POST https://management.core.windows.net//services/hostedservices//deployments/

Response


 

 
endpoint-set-name
 
local-port-number
 
external-port-number
 

 
path-of-probe
 
port-assigned-to-probe
 
probe-protocol
 
interval-of-probe
 
timeout-for-probe
 

 
name-of-internal-loadbalancer
 
endpoint-protocol
 
15
 
enable-direct-server-return
 

 

 

 
priority-of-the-rule
 
permit-rule
 
subnet-of-the-rule
 
description-of-the-rule
 

 

 

 

 

WE ARE MICROSOFT

Explore Microsoft Foundry

The future of AI starts here. Envision your next great AI app with the latest technologies. Get started with Azure.