Ec2 streamlit stuck on loading screen while running streamlit hello

Unfortunately, ā€œenableCORS=falseā€ doesnā€™t work.

After setting this option, I still get ā€œPlease waitā€¦ā€ screen when trying to connect to my EC2 (Iā€™ve checked that the config is loaded properly via ā€˜streamlit config showā€™ and my 8501 port is open)

Iā€™ve also tried binding it to 0.0.0.0 like when I deploy gunicorn (browser.serverAddress=ā€œ0.0.0.0ā€), as per How do I set the server to 0.0.0.0 for deployment using Docker

Not sure if itā€™s relevant, but when I try the /healthz route, I get ā€œOKā€.

Any other ideas on how to resolve this?
Iā€™ve encountered the same issue on several other EC2 instances I tried. I was so excited to showcase your amazing app to our team tomorrow :cry:
(but regardless of this issue - this is an amazing tool, guys!! :+1:)

Update: It works when I run streamlit on localhost on EC2 (browser.serverAddress=ā€œlocalhostā€) and forward my port via SSH tunnel. But I still havenā€™t found a way how to make it accessible on instanceā€™s public IP.

Update 2: I just got home and got a very strange behaviour.

  • At first, it was hanging at ā€œplease waitā€¦ā€ and I could see that ā€˜/streamā€™ call to websocket is timing out.
  • But after a while (c. 2mins) Hello app suddenly popped up (ā€™/streamā€™ went through with status code 101). I could replicate this behaviour several times (a few mins of time outs and then pop up).
  • Now, when I refresh it loads immediately! I havenā€™t done any changes on EC2 (config is set to enableCORS=false, serverAddress=ā€˜0.0.0.0ā€™)

Update 3: It again stopped working this morning (despite no changes). Since then, Iā€™ve tried multiple AWS accounts, regions, set ups and streamlit apps with no difference. Winning combo (when it works) is as per my Update 2, but itā€™s quite temperamental, which makes it hard to reproduce & debugā€¦ I guess Iā€™ll wait for a more stable release (EC2-wise).

For completeness: Issue is on path /stream that keeps hitting ā€œWebSocket is closed before the connection is established.ā€ and over time changes into ā€œError during WebSocket handshake: Unexpected response code: 503ā€

Update 4: Temporary solution seems to be to put your EC2 behind an ALB that forwards from port 80 to whatever your Streamlit port is (eg, 8501).

2 Likes