falcon: Failed to upgrade to WebSocket

I’m hoping I missed an obvious step, and am posting here before I dive in deeper.

Full message here:

Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, Upgrade, HTTP_UPGRADE: )
Finished "/cable"[non-WebSocket] for 127.0.0.1 at 2023-03-22 08:37:13 -0600

Context: I’m exploring what it would take (if anything) to support Falcon servers running on fly.io. I started with Demo 3 which you can run on your own machine if you have Rails 7, Docker, Redis, and Postgres installed - simply copy and paste the script into an empty directory.

It starts out with Puma. If you open two browser windows and press refresh a visitor counter will update in both. Simple stuff.

Next, run:

bundle remove puma
bundle add falcon

And restart the server and the websocket fails to start.

In order to debug this, I repeated this with the latest Rails main, which I instrumented with log statements. It seems that websocket_possible? is nil at the following line https://github.com/rails/rails/blob/355fd5929058ee3a73032c5f62de3d8819550482/actioncable/lib/action_cable/connection/base.rb#L75; this in turn is because ::WebSocket::Driver.websocket?(env) is false at https://github.com/rails/rails/blob/355fd5929058ee3a73032c5f62de3d8819550482/actioncable/lib/action_cable/connection/web_socket.rb#L10

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 19 (11 by maintainers)

Commits related to this issue

Most upvoted comments

also running into this now. anyone managed to find out what’s happening?

Yooo just tuning in to say that adding protocol-rack 0.4.1 to my Gemfile seems to have solved the issue. supercool 👍

I released v0.4.1 which has the fixes discussed above, except the server will still print the warning which you can ignore.

Thank you ! Now it work like a charm ❤️ I will test further

I released v0.4.1 which has the fixes discussed above, except the server will still print the warning which you can ignore.

Hi! I just ran into this issue as well. If there’s an obvious step, I also missed it, I get the same error.

Kind of weird that ::WebSocket::Driver.websocket? would return false, as it’s super generic and not changed for 9 years:

    def self.websocket?(env)
      connection = env['HTTP_CONNECTION'] || ''
      upgrade    = env['HTTP_UPGRADE']    || ''

      env['REQUEST_METHOD'] == 'GET' and
      connection.downcase.split(/ *, */).include?('upgrade') and
      upgrade.downcase == 'websocket'
    end

Does env get mangled somehow?