SSL connection has been closed unexpectedly

Hi @Sinakian , as @Caroline said it’s difficult to understand your question without some code.

However, I think your problem could be related to the PostgreSQL connection closing because it timed out. If I understand correctly, as of version 1.17, the @st.experimental_singleton decorator supports a validate parameter to solve this.

In a previous version I made a simple adjustment to my app:

@st.experimental_singleton
def init_connection(reloadvar):
    return psycopg2.connect(**st.secrets["postgres"])

# Add boolean var as argument of function
reloadvar = False
conn = init_connection(reloadvar)

# Reconnect button, if necessary
if st.button(label='Reconnect'):
    reloadvar = not(reloadvar)
    conn = init_connection(reloadvar)

Basically, the cache decorators would only run the function if an input argument changes. So I just added an input argument so the user can restablish the connection if needed to.

This is not the most elegant solution and I’m quite sure something better could be made using the session_state, but it worked for me that time.

Hope that helps.