Session state persists across different users/tabs/devices

Hello Streamliters,

I have recently encountered an odd scenario where the session state persists across multiple sessions (different tabs, different browsers, different devices). I have seen this issue in a few other forum posts but no solution was found. After some testing I managed to find the cause, so hopefully this will help others who encounter this issue.

The app in question is deployed on a remote Linux server, and it’s using Streamlit version 1.30.0 (though I have noticed this with earlier versions as well). Unfortunately I cannot share the code but I can say that no information is being cached with st.cache (I have seen from other forum posts that this causes similar behavior).

The cause
I have some logout/reset buttons in my app that basically clear out any data saved in the session state. To achieve this I was doing the following - basically making the session state an empty dictionary.

st.session_state = {}

Resetting the session state this way seems to cause this behavior, which can’t be resolved unless the app is restarted.

The solution
To avoid the issue I am resetting the session state like so. This implementation has the same result as the above but doesn’t trigger the shared sessions state issue.

for key in st.session_state:
    st.session_state.pop(key)
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.