Connection Error on Local Streamlit App - Works on Streamlit Cloud

Issue Description:
I have developed a Streamlit application for helping coaches. The app works flawlessly when deployed via GitHub on Streamlit Cloud, but I encounter persistent connection issues when running it locally on my machine.

Environment:
-OS: Windows 10
-Python Version: 3.10
-Streamlit Version: Latest

Issue
When I execute streamlit run app.py in my VS terminal, the app opens in my local http://localhost:8501. I see my app. But when I press, an actionable button (e.g., “Generate”), the app runs (indicated by “RUNNING” status), but then it hangs with a “CONNECTING” message in the upper right corner. Eventually, I receive the following error:
Connection error
Is Streamlit still running? If you accidentally stopped Streamlit, just restart it in your terminal:
I get the same message every time I try to execute the app from the terminal.

Steps Taken:

  • Cleared Streamlit cache programmatically using st.cache_data.clear().
  • Cleared browser history and cache (Google Chrome).
  • Simplified button callback to isolate the issue.
  • Added logging and diagnostics to trace the problem, identifying it might be related to solver.Solve(model) in the CP-SAT solver from OR-Tools.

Imports
import streamlit as st
import pandas as pd
from ortools.sat.python import cp_model
import random
from datetime import datetime
import uuid
import subprocess
import pyarrow as pa
import logging
import os

Code Snippet:
When, I press the Generate button in the app:
if st.button(“Generate Lineup”):
model, lineup_vars = create_model(players, positions, skills)
st.session_state.lineup_df = solve_lineup_model(model, vars, players, skills, team_name)
st.session_state.lineup_generated = True,

Based on some debugging print lines, the app hangs during this function call:

Function to solve the model

def solve_lineup_model(model, vars, players, skills, team_name):
try:
st.markdown(‘

Starting to solve the model…
’, unsafe_allow_html=True)
solver = cp_model.CpSolver()
status = solver.Solve(model)
st.markdown(‘
Checking on the status…
’, unsafe_allow_html=True)
if status == cp_model.OPTIMAL or status == cp_model.FEASIBLE:
code continues…
The app never gets to display the print statement - Checking on the status…

Notes:

  • The issue seems to happen at the line status = solver.Solve(model), as the code never progresses beyond this point. However, since the same code/library runs in the deployed cloud app, it seems unlikely that the issue is related to the OR-Tools CP-SAT solver.
  • This function runs - and same entire python code - without issues on the Streamlit Cloud deployment via GitHub but fails locally now. Note that it used to run just fine locally a couple days ago with the same python code

Questions:

  1. Has anyone encountered a similar issue with Streamlit?
  2. Could this be related to local environment configuration or some underlying resource constraint?
  3. Any other suggestions or debugging steps I should consider?

I appreciate any insights or suggestions the community can provide.

Hi @Steven3 , did you identify the source of the issue here? I am experiencing the same issue. I’m new to streamlit and not sure where to dig.

Hi @Steven3,
I am running in the same error. The error also occurs when loading a model. My 2 cents is that I think Streamlit is getting overloaded with large files/models. I have attempted to use st.cache_resource decorators, but to no avail. If anyone has a solution, I’d love to hear it!

The code snippet breaking streamlit (1.28.2; upgrading the library didn’t work)
results = vector_store.similarity_search_by_vector(query_embedding, k=top_k)

update: after some fooling around, it turns out that my error was the result of faulty python code that persisted even when running outside of a streamlit environment.

I am running in the same error.

Good day. Thanks for everybody’s comments and feedback. It appears that this issue has occured with others too. Good news, is that I no longer have the “connect” issues that I had documented. The bad news, is that it was a few months ago and I don’t exactly remember the actions that I did in order to remedy the issue. I even reviewed my notes this am but nothing of importance. Today, the app properly runs on my local terminal and the Streamlit Community. Some users/coaches are already testing the app to see if it can help them too. If I recall, there was no major “aha” moment or comprehensive code redo. In fact, I think my solution at the time had more to with rebooting my local computer, restarting VS, and restarting Streamlit. I apologize for the very non-descript, non-technical recollection. I am not a programmer by trade and this project started with my need as a little league coach to have an app help me develop my team game lineups quickly, efficiently and effectively. Nonetheless, perhaps the underlying message is that the problem was indeed remedied. I hope everybody is able to fix their issues similarly and if anybody here has more illumination on their solutions, please provide any update for the benefit of the others. Thanks

Hi streamlit team can you please help us look into this issue, ive been having the same error this year kindly see the error in the screenshot. when ever i do a handshake it just hangs with the connecting error. I dont know how to debug this any longer.