firehoseio / firehose

Build realtime Ruby web applications. Created by the fine folks at Poll Everywhere.
http://firehose.io/
MIT License
727 stars 72 forks source link

Problem using the consumer #29

Closed nirnanaaa closed 10 years ago

nirnanaaa commented 10 years ago

Hi,

I want to use the consumer as described in the README.

My consumer.ru file:

~/code/firehose_c% cat consumer.ru 
require 'firehose'
consumer = Firehose::Rack::Consumer.new do |app|
  app.http_long_poll.timeout = 20
end

run consumer

In my Gemfile I have locked rainbows to 4.4.3 and using the git checkout of firehose.

I start up rainbows now by calling:

rainbows consumer.ru -p 7474

Anyway if I try to connect via the Javascript library I am just getting this error message in the rainbows log:

127.0.0.1 - - [30/Oct/2013 07:19:46] "HEAD /LrMzsvbdNgA3RmrsjFuG HTTP/1.1" 500 70112 0.0232
Rack::Lint::LintError: rack.hijack must respond to call
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/lint.rb:20:in `assert'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/lint.rb:459:in `check_hijack'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/lint.rb:238:in `check_env'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/lint.rb:43:in `_call'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/lint.rb:37:in `call'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/showexceptions.rb:24:in `call'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/chunked.rb:43:in `call'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.4.3/lib/rainbows/max_body.rb:66:in `block in call'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.4.3/lib/rainbows/max_body.rb:59:in `catch'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.4.3/lib/rainbows/max_body.rb:59:in `call'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.4.3/lib/rainbows/process_client.rb:43:in `process_loop'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.4.3/lib/rainbows/base.rb:32:in `process_client'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:632:in `worker_loop'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.4.3/lib/rainbows/http_server.rb:45:in `worker_loop'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.4.3/lib/rainbows/http_server.rb:61:in `spawn_missing_workers'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:142:in `start'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/gems/rainbows-4.4.3/bin/rainbows:122:in `<top (required)>'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/bin/rainbows:23:in `load'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/bin/rainbows:23:in `<main>'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `eval'
    /Users/nirnanaaa/.rvm/gems/ruby-2.0.0-p247/bin/ruby_noexec_wrapper:14:in `<main>'

And the browsers console just throws this:

XMLHttpRequest cannot load http://localhost:7474/LrMzsvbdNgA3RmrsjFuG. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:3000' is therefore not allowed access. 

If I start the consumer in thin I get this in my thin log:

[2013-10-30 06:31:39.590 #3869] DEBUG : WS connection `/LrMzsvbdNgA3RmrsjFuG` closing. Code: 1006; Reason ""

And an Upgrade header missing in my Browsers console.

Redis version:

Redis server v=2.6.16 sha=00000000:0 malloc=libc bits=64

Ruby:

~/code/firehose_c% ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.5.0]

Have I done something wrong or am I missing something?

bradgessler commented 10 years ago

Yeah, run rainbows via bundle exec rainbows consumer.ru -p 7474 and make sure its the right version. I believe you're running rainbows 4.5 since versions prior don't work with the rack.hijack API.

We're working on getting this working with rainbows 4.5 with issue https://github.com/polleverywhere/firehose/issues/22. The problem is that we're running into some low-level EM issues in the test suite.

nirnanaaa commented 10 years ago

I don't get it. bundle exec rainbows consumer.ru -p 7474 as you have mentioned above throws the exact same errors.

Rainbows version with bundle prefixed:

~/code/firehose[master*]% bundle exec rainbows -v                 
Rainbows! v4.4.3

You can also see in the example above, that this was also 4.4.3

nirnanaaa commented 10 years ago

Even if I run the bin/firehose server in the same directory as the bundle exec rainbows I am getting these errors.

bradgessler commented 10 years ago

What happens if you run via https://gist.github.com/bradgessler/f2416efdbb1771e983b3

I think newest version of Rack::Lint might not be compatible with older version of Rainbows. You might try bumping the version of rack down below 1.5.x series and running in dev mode (production removes the Lint middleware)

nirnanaaa commented 10 years ago

Okay strange this seems to work.

Locking Rack down to 1.4.5 resulted in another error about content type missing or something.

Without the

require 'faye/websocket'
Faye::WebSocket.load_adapter('rainbows')

It results in the same kind of error as when using thin.

Seems like I need to specify the environment in rainbows. Otherwise the above error will happen. I think I don't need the dev env.

The -c rainbows.conf can be skipped in my case.

Thanks a lot for your help.

bradgessler commented 10 years ago

The

require 'faye/websocket'
Faye::WebSocket.load_adapter('rainbows')

business is required for everything prior to rack 1.5.x because it monkey patches rack.hijack. Looks like I need to change the rack dependency on the gem to ~> 1.4.0 in the firehose 1.2.x series.

bradgessler commented 10 years ago

I just cut a 1.2.10 release of the firehose gem that tightens up these dependencies http://rubygems.org/gems/firehose

I'll release 1.3.0 when rainbows 4.5 compatibility is working.

nirnanaaa commented 10 years ago

I think the rack version does not matter. Even if i use rack 1.4.0 I am getting errors in development mode:

Rack::Lint::LintError: Status must be >=100 seen as integer

Production works just fine as Rack::Lint is not used.

Also the -c switch seems to be necessary

bradgessler commented 10 years ago

Yeah, deep underneath the covers rack returns a status code of -1 to signal that the body is a block so that the response can be streamed. I believe rack.hijack changes this behavior, but I need to upgrade to Rainbows! 4.5 for that to work properly.