NAT Gateway is a fully managed service that securely routes internet traffic from a private virtual network with enterprise-grade performance and low latency.
Hello @Andrés
Thank you for reaching out to Microsoft Q&A.
Based on the behavior you've described, the observed connection resets are consistent with the documented design of Azure NAT Gateway. When a TCP connection remains idle longer than the configured idle timeout (4 minutes by default), the NAT Gateway removes the associated SNAT flow state. The connection is not proactively closed with a TCP FIN or RST packet at the time the idle timeout expires. As a result, applications that attempt to reuse an idle pooled connection may encounter connection reset errors once traffic resumes.
From an infrastructure perspective, there is currently no NAT Gateway feature that sends immediate connection termination notifications to both endpoints when idle flow state is removed.
For workloads that rely on persistent outbound HTTPS connections, Microsoft generally recommends one of the following approaches:
- Configure application-level connection pool idle timeouts or connection lifetimes to be shorter than the NAT Gateway idle timeout.
Enable TCP keepalive so that idle connections periodically send traffic and remain active from the NAT Gateway's perspective.
Increase the NAT Gateway idle timeout where appropriate, while monitoring SNAT port consumption, as longer timeouts keep ports allocated for a longer duration.
For AKS workloads where individual applications do not expose connection pool settings, configuring OS-level TCP keepalive parameters through AKS Linux OS configuration is a supported mitigation. TCP keepalive probes can help prevent connections from becoming idle long enough for the NAT Gateway to remove the flow state.
Based on your testing results, increasing the NAT Gateway idle timeout and ensuring connection lifetime or keepalive settings remain below that threshold is a reasonable and supported approach for applications that maintain long-lived outbound connections.
Reference documentation:
- https://learn.microsoft.com/azure/virtual-network/nat-gateway/nat-gateway-resource
- https://learn.microsoft.com/azure/aks/improve-network-fault-tolerance-in-aks-using-tcp-keepalive
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".