Getting a broken pipe error with websockets

We recently added a simple Turbo Stream based feature to our app. We had to make changes to our Nginx config to allow for websockets, but the feature seems to work as expected.

However, now we get these errors often: [ERROR] WebSocket error occurred: Broken pipe. Occasionally I will see [ERROR] Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: close, HTTP_UPGRADE: )

They seem to occur with every successful connection. They also seem to be low-level because exceptions are not caught by our exception tracker.

I’m guessing something is disconnecting abruptly rather than correctly closing the connection. Like I said the feature works, so it seems communication is happening between clients and the server. I suspect it could be an issue with my load balancer or Nginx config.

I am tempted to ignore this error, but has anyone else dealt with this problem?

Every time I see problems like this, I can usually trace it back to Redis being flaky, or the web server not being configured correctly for the wss:// protocol.


I wouldn’t have expected Redis, but I suppose the “pipe” could be breaking in a direction that I wasn’t expecting.

My Nginx config for /cable looks like this:

location /cable {
  proxy_pass http://my_app_proxy/cable;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection $connection_upgrade;

  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto https;
  proxy_set_header Host $http_host;

—which is based on what I could find by Googling. Do you see anything wrong with it? Do you have any general recommendations for a better way to set up ActionCable?