Streamlit reruns all 30 seconds

Hi! First, thank you to the community because Streamlit is really the tool I was looking for. :slight_smile:
I have deployed a Streamlit app on GCP in a Kubernetes cluster following this tutorial. The app is running in a docker and every thing is working well.
However, I do not know why but when I visit the website, every 30 seconds I can see /healthz and /stream GET requests and the app reruns alone without doing anything. I could not reproduce this behavior locally…
Do you have any idea of the reason why the app reruns every 30 seconds?

@Remi_Verdier Did you find a solution for this? I am having the same issue right now, and the reloading really makes the app uncomfortable to use. I also can’t reproduce this locally inside the same container.

Hi @Adem, indeed I found a solution !
You have to configure a k8s backend service to increase the socket connection timeout (default is 30 seconds). This is the example I used, setting the timeout to 1 hour. You just have to copy it in your ingress.yaml for example.

Thank you for the quick reply!

Before even reading your response I actually somehow found out that it could have something to do with the configuration for websocket applications.

Maybe this will help others also, but on top of the timeout, I actually updated the backed to use a generated cookie to identify the user session and not reload the page in case it is coming from the same user (resulting in not reloading the app).

This tutorial was useful: https://medium.com/k8scaleio/running-websocket-app-on-kubernetes-2e13eabb4c4f

But I actually went with

    spec:
      sessionAffinity:
        affinityType: "GENERATED_COOKIE"
      timeoutSec: 300
      connectionDraining:
        drainingTimeoutSec: 600

to generate a cookie instead of relying on the IP for user identification (in case multiple people try to access the app through a proxy)

For different types of backend affinity also see: https://cloud.google.com/load-balancing/docs/backend-service#session_affinity

Edit:
Apparently I was a little too confident here. After the timeout the reloading happens anyways, so the affinity doesn’t seem to change anything. So I just went with a higher timeout for now as suggested before, which kind of fixes the issue.