Server-sent events and Azure Application Gateway for Containers
I have a server that supports server-sent events. When running this server locally, everything works as expected.
But as soon as I deploy it in an AKS Kubernetes cluster in front of an Azure Application Gateway for Containers, the SSE connection times out after 60 seconds. After some research, I found the following documentation: https://learn.microsoft.com/en-us/azure/application-gateway/for-containers/server-sent-events?tabs=server-sent-events-gateway-api. There it's stated that you should create a RoutePolicy
and configure a timeout of 0s. But doing so doesn't change anything. The observed timeout remains 60s.
I then played around with the RoutePolicy
a bit. And in case the timeout is higher than 0s and lower than 300s, the RoutePolicy
works. But (as mentioned above) 0s doesn't seem to do anything at all. And any value greater than 300s leads to a 300s timeout. So the 300s appears to be the maximum.
Kubernetes version: 1.29.11.
alb-controller Helm Chart version: 1.3.7
I created a minimal example, which you can find on GitHub: https://github.com/tnotheis/SseServerTest
You can run the SSE server locally with the following command:
dotnet run dotnet run -p .\SseServerTest\SseServerTest.csproj
Afterwards, open http://localhost:5293/sse in your browser. You will receive 1 event per second, which makes it easy to see after which time a timeout occurs.
You will notice that, when running it locally, there will never be a timeout.
I further added a kubernetes.yaml file, which contains all Kubernetes resources necessary to deploy the application into a cluster with an already existing Azure Application Gateway for Containers. Just make sure to replace the name of the gateway
resource as well as the hostname (both places are marked with TODO
comments).