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