GithubHelp home page GithubHelp logo

Failed to upgrade to WebSocket about falcon HOT 19 CLOSED

rubys avatar rubys commented on May 25, 2024 1
Failed to upgrade to WebSocket

from falcon.

Comments (19)

buhrmi avatar buhrmi commented on May 25, 2024 2

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

from falcon.

tinco avatar tinco commented on May 25, 2024 1

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?

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024 1

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

from falcon.

Pash-tet avatar Pash-tet commented on May 25, 2024 1

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

from falcon.

buhrmi avatar buhrmi commented on May 25, 2024 1

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

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024 1

Thanks for the reports of success. As such, I'll close this issue. Feel free to open a new issue if you find other problems.

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

I will take a look, thanks for the detailed information.

from falcon.

tinco avatar tinco commented on May 25, 2024

Oh actually there's a hint in the logged message:

Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, Upgrade, HTTP_UPGRADE: )

Note how the HTTP_UPGRADE is empty, and instead there's an Upgrade in HTTP_CONNECTION instead..

edit: Nvm, upgrade should to be there. But in the HTTP_UPGRADE there's supposed to be a websocket string as well.

from falcon.

Amnesthesia avatar Amnesthesia commented on May 25, 2024

11:56:29 E ActionCable -- Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: ) we're running into this too, we can't really use Falcon without nginx because of this

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

Thanks for the reminder, I'll take a look.

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

I believe this is a similar issue to socketry/async-websocket#55

If possible, can someone test adding the following middleware to see if it resolves the issue:

class RackProtocolToConnectionUpgrade
  def initialize(app)
    @app = app
  end

  def call(env)
    if protocol = env['rack.protocol']
      env['HTTP_UPGRADE'] = protocol
      # Maybe need to modify connection header too.
    end

    @app.call(env)
  end
end

This won't work for HTTP/2 however...

from falcon.

Pash-tet avatar Pash-tet commented on May 25, 2024

I have same problem, action cable not working on rails 7.1.2 with falcon. Tried to use middleware - same result, with middleware https://github.com/rails/rails/blob/355fd5929058ee3a73032c5f62de3d8819550482/actioncable/lib/action_cable/connection/stream.rb#L97C56-L97C56 @socket_object.env["rack.hijack"] return nil

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

Thanks for the reports, after thinking about this problem, I'll try to address it directly in protocol-rack with a compatibility shim.

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

Apologies, I've realised the issue here. Full hijack is not supported by protocol-rack. I'll look into potential solutions. In the past it was supported, but it's replaced by full-bidirectional streaming in Rack 3 and that's what falcon provides out of the box since it's a better abstraction. I'll consider if there is an easy way to make this work with ActionCable.

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

After playing around with it, it wasn't so hard to restore full hijack support. This should work. However, I don't think full hijack is a good long term solution for Falcon. Can you please try protocol-rack v0.4+ and it should work.

from falcon.

Pash-tet avatar Pash-tet commented on May 25, 2024

After playing around with it, it wasn't so hard to restore full hijack support. This should work. However, I don't think full hijack is a good long term solution for Falcon. Can you please try protocol-rack v0.4+ and it should work.

Hello, i tried with protocol-rack v0.4+.

First i got error on this line https://github.com/socketry/protocol-rack/blob/3a9ff0ef95198c3e4070c723ce54bc63d7dd4074/lib/protocol/rack/adapter/generic.rb#L77
NameError: uninitialized constant Protocol::Rack::Adapter::Generic::RACK_HIJACK. I rewrite it to Protocol::Rack::Adapter::Rack2::RACK_HIJACK and this error is gone.

Then i got error in middleware env['HTTP_UPGRADE'] = protocol, change to env['HTTP_UPGRADE'] = protocol.first, this fix second error.

Then i got this error, and i stuck on it (

warn: Async::Task: Reading HTTP/1.1 requests for Async::HTTP::Protocol::HTTP1::Server. [oid=0x4a10] [ec=0x3a5c] [pid=12191] [2023-12-11 10:12:59 +0300]
               | Task may have ended with unhandled exception.
               |   NoMethodError: undefined method `write' for nil:NilClass
               |   → .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/protocol-http1-0.16.0/lib/protocol/http1/connection.rb:126 in `write_response'
               |     .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/async-http-0.61.0/lib/async/http/protocol/http1/server.rb:63 in `each'
               |     .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/async-http-0.61.0/lib/async/http/server.rb:40 in `accept'
               |     .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/async-io-1.38.0/lib/async/io/server.rb:15 in `block in accept_each'
               |     .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/async-io-1.38.0/lib/async/io/socket.rb:58 in `block in accept'
               |     .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/async-2.6.5/lib/async/task.rb:160 in `block in run'
               |     .rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/async-2.6.5/lib/async/task.rb:330 in `block in schedule'

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

Just to confirm, you are using Rack 3+ right?

Oh, also, that "warning" you can ignore for now, it's because the connection got hijacked and it can't write a normal response, it's noisy but shouldn't impact the websocket.

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

Ohhhh it looks like I put the constant in the wrong place... hold on, let me fix that.

from falcon.

ioquatix avatar ioquatix commented on May 25, 2024

Ah, you no longer need the middleware proposed on this issue either, so you can remove that completely.

from falcon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.