K8 - Error during WebSocket handshake: Unexpected response code: 200

Fails while trying to connect to streamlit server in k8. In chrome console I get WebSocket connection to failed: Error during WebSocket handshake: Unexpected response code: 200 and in the UI I get Connection failed with status 200: User healthz is not active. You don't have access to any of healthz's projects.

The stdout logs have no errors. Running 0.47.4.

This may be related to Connection error when deploying using docker on k8s. I already have enableCORS = false set. I also see in network tab a call to http://mydomain.example.com:0/healthz every second, is that normal? Literally every 1s. When I see a chrome preview of one of these calls I also see a User healthz is not active. You don't have access to any of healthz's projects.

So I guess my questions are…

  1. Any ideas?
  2. What exactly is it trying to connect to and how? Do I need to set certain service/ingress/ports in k8?
  3. Why is it spamming /healthz ?

Hi @alee

Can you give a little more information about your Kubernetes setup? Or, even better: can you provide steps to reproduce your setup? (if possible!)

I haven’t seen those error messages before, but I believe they’re coming from somewhere in your k8s infrastructure. It’s hard to tell without knowing your exact setup but my guess is that somewhere in your settings you need to open access to these 3 endpoints: /healthz, /stream, and /message.

Ok, nerd time :nerd_face:. In case you’re curious about what those endpoints do, here’s a quick description:

Streamlit apps need to access to a few different routes in the Streamlit server. Most data between the server and the app is communicated via a websocket connection at the /stream endpoint. But before the websocket connection is established (and also any time it goes down), the app continuously pings the server at /healthz to see if should try to reconnect the websocket.

There’s also another endpoint at /message which is used to cache messages sent back and forth between the server and the app. I’m not going to go into much detail about what this does, but the high level bit is that it improves Streamlit’s performance.

This is all probably TMI, but I thought you (or others!) may be curious about why these endpoints exist :smiley:

And just because I spend 5 minutes doing some ASCII art, here’s a diagram of the whole thing:

(Terminal)                                       (Browser)

+------------------+                             +------------------+
| Strealmit server |                             | Streamlit app    |
|                  |                             |                  |
| Routes:          |                             |                  |
| /                |<- HTML/JS/CSS assets -------|                  |
| /healthz         |<- Server "is-alive" check --|                  |
| /stream          |<- Websocket connection -----|                  |
| /message         |<- Packet cache -------------|                  |
|                  |                             |                  |
+------------------+                             +------------------+

Hi @alee

Could you verify you’re on Streamlit version 0.47.4?

If you’re hitting http://mydomain.example.com:0/healthz there was a bug fix that landed in 0.47.4 that hits the correct port instead of port 0 as is happening for you now.