Memory exhaustion from orphaned session states in low-traffic environments
0 reputation · 24 Oct 2022, 04:40 UTC
When deploying Streamlit applications on minimal-tier cloud instances, memory consumption often climbs steadily despite low active user counts. While @st.cache_data is utilized to minimize redundant compute, the server-side session state persists for every connection, consuming significant RAM.
The concern arises because Streamlit relies on browser-side heartbeats to trigger session termination. In scenarios where a user closes a tab without a formal logout, the server-side resources associated with that session may remain allocated longer than necessary, potentially leading to Out-of-Memory (OOM) errors on resource-constrained hardware.
Is there a configuration parameter to define a strict server-side timeout for session cleanup, and can we programmatically force the clearance of session-state objects when a heartbeat is missed?