Summary of the issue:

  1. Connecting to test.mosquitto.org or iot.eclipse.org with a keep alive of more than 5 minutes, and everything seems to work just as expected.

  2. Connecting to my broker (both on Azure hosted VMs - one is Mosquitto and one is Emqttd), my clients don't send a ping if the keep-alive is longer than 5 minutes. They just die. The broker disconnects them eventually for not pinging. I'm not using an Azure load balancer, I'm connecting directly to the VM).

The thing is, the connected device doesn't know it's been disconnected if its over a cell network (not sure why?)

Over an Ethernet network, it'll reconnect itself as it should.

Not sure if there is something unique about the Azure VM's that is causing my disconnection/timeout issue with longer keep-alives?

Lastly, if I use a 2 minutes or shorter keep-alive, everything works.

  • 2
    It's only a guess, but I would think it might be in the Azure firewall/router has an inactivity timer on it's routing/forwarding to the actual host machines.
    – hardillb
    Commented Mar 7, 2018 at 19:42
  • Your comments got me thinking and I found this: stackoverflow.com/questions/16840834/…
    – Nate Caleb
    Commented Mar 7, 2018 at 21:58

3 Answers 3


I found my issue and how to fix it. Posting as an answer here for completeness in case others have similar issues.

Azure virtual machines (Resource Manager, not classic) can be created with a public ip address. This is where the idle timeout is managed. It is defaulted to 4 minutes.

If you click on the ip address in the portal, you'll be taken to the public ip blade for that VM.

Select Configuration in the menu to see that blade. There is a slider labeled "Idle timeout (minutes)." Adjust that and click save at the top.

Alternatively, this can be configured via powershell

    Set-AzureRmContext -SubscriptionId "subscription name"
    $publicIpAddress = Get-AzureRmPublicIPAddress -Name "ip address name" -ResourceGroupName "resource group name"
    $publicIpAddress.IdleTimeoutInMinutes = 29
    Set-AzureRmPublicIpAddress -PublicIpAddress $publicIpAddress

Just to complete this question.

As worked out in the comments. It looks like Azure's router drops connections that have been idle for 5 mins. See this Stack Overflow answer for details: https://stackoverflow.com/questions/16840834/are-established-network-connections-to-azure-endpoint-terminated-by-firewall-or




I can't remember where I captured this from, so I'm unable to link to source. All pinpoint accurate information though.

Yes, Microsoft should bake in more appropriate values into their Azure Linux images.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.