Streamlit app on kubernetes keeps refreshing every 30 seconds


I have created a simple app which is deployed on k8s. Its an app which is intended for downloading data.
I have observed that it keeps refreshing every 30 seconds, which is not acceptable as we need time to select date and time.
Also I see that it happens only when access via ingress, if I port forward the service then it keeps working ok.
I was wondering it may be because of hard coded value in tornado settings in streamlit/web/server/
But I was wrong :frowning:
TORNADO_SETTINGS = { # Gzip HTTP responses. "compress_response": True, # Ping every 1s to keep WS alive. # 2021.06.22: this value was previously 20s, and was causing # connection instability for a small number of users. This smaller # ping_interval fixes that instability. # "websocket_ping_interval": 1, # If we don't get a ping response within 30s, the connection # is timed out. "websocket_ping_timeout": 30, }

We run k8s on our own server so the work around mentioned in this post is not relevant. Probably Iโ€™m doing something absolutely wrong :slight_smile:

Finally we found out that issue was due to the default time out of gcp load balancer, which was causing the web socket connection to re-initialize every 30 secs. All we needed to do was change the time out in the backend configuration of load balancer. I hope it helps.

1 Like

Is there a way to increase the request time out? Like 1 day. Because the max in gcp is 1hr only. The interaction in my app could take like 4hrs.

Hey can you tell how you solved in the GCP side and were using nginix?

Hello Ikarimov,
Indeed that is annoying. I fixed by navigating to Network Services -->Load Balancing , then click on edit the button on top next to load balancer details. Click on backend configuration, select the backend service being used and click on edit.
Youโ€™ll see timeout is set to 30 seconds, increase this value to your desired value and save.
Thatโ€™s it. Reload your app in new session it should work.
I know its hacky but Iโ€™m pretty sure it is configurable via gcloud sdk but I didnโ€™t really had the time to do that.
I hope it helps, good luck!

Hi Stephen,
I hope you found the solution, I was able to set value higher than 1 hr without any issue.