undefined method `close_connection_after_writing' for nil:NilClass (NoMethodError) #128

Closed
codezomb opened this Issue Feb 28, 2012 · 5 comments

Comments

Projects
None yet
3 participants
@codezomb

This is similar to issue #116, but I'm not using nginx. I've encountered this using another gem that relies on faye 0.8.0, called private_pub from Ryan Bates, and I've submitted an issue there.

ryanb/private_pub#39

Sample rails app that demonstrates the behavior:
https://github.com/gitt/private_pub_test

This happens when a POST request is made to localhost:9292/faye on OSX 10.7.3.

Versions are as follows:

faye (0.8.0)
  cookiejar (>= 0.3.0)
  em-http-request (>= 0.3.0)
  eventmachine (>= 0.12.0)
  faye-websocket (>= 0.4.0)
  rack (>= 1.0.0)
  yajl-ruby (>= 1.0.0)
faye-websocket (0.4.1)

Faye is launched using a rackup file

# Run with: rackup private_pub.ru -s thin -E production
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"

PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
run PrivatePub.faye_app
/Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/faye-websocket-0.4.1/lib/faye/websocket/api.rb:75:in `block in close': undefined method `close_connection_after_writing' for nil:NilClass (NoMethodError)
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/faye-websocket-0.4.1/lib/faye/websocket/api.rb:89:in `call'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/faye-websocket-0.4.1/lib/faye/websocket/api.rb:89:in `close'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/faye-websocket-0.4.1/lib/faye/websocket.rb:177:in `fail'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/thin-1.3.1/lib/thin/connection.rb:155:in `unbind'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:1397:in `event_callback'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:179:in `run_machine'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:179:in `run'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/thin-1.3.1/lib/thin/backends/base.rb:61:in `start'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/thin-1.3.1/lib/thin/server.rb:159:in `start'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/rack-1.3.6/lib/rack/handler/thin.rb:13:in `run'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/rack-1.3.6/lib/rack/server.rb:265:in `start'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/rack-1.3.6/lib/rack/server.rb:137:in `start'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/gems/rack-1.3.6/bin/rackup:4:in `<top (required)>'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/bin/rackup:19:in `load'
    from /Users/mike/.rvm/gems/ruby-1.9.2-head@private_pub_test/bin/rackup:19:in `<main>'
@jcoglan

This comment has been minimized.

Show comment
Hide comment
@jcoglan

jcoglan Feb 28, 2012

Collaborator

You need to either boot the application with the thin command, or tell it you're using Thin. This is because faye-websocket now supports multiple web servers, all of which need monkey-patching to support sockets. Amend your config to:

require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"

Faye::WebSocket.load_adapter('thin')

PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
run PrivatePub.faye_app

Let me know if this fixes the problem.

Collaborator

jcoglan commented Feb 28, 2012

You need to either boot the application with the thin command, or tell it you're using Thin. This is because faye-websocket now supports multiple web servers, all of which need monkey-patching to support sockets. Amend your config to:

require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"

Faye::WebSocket.load_adapter('thin')

PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
run PrivatePub.faye_app

Let me know if this fixes the problem.

@codezomb

This comment has been minimized.

Show comment
Hide comment
@codezomb

codezomb Feb 28, 2012

Sorry, I thought included this below that file. I startup the server using:

bundle exec rackup private_pub.ru -s thin -E production

My rails app is started seperately

bundle exec rails s thin

Sorry, I thought included this below that file. I startup the server using:

bundle exec rackup private_pub.ru -s thin -E production

My rails app is started seperately

bundle exec rails s thin
@codezomb

This comment has been minimized.

Show comment
Hide comment
@codezomb

codezomb Feb 28, 2012

This does appear to resolve the issue, thanks!

This does appear to resolve the issue, thanks!

@jcoglan

This comment has been minimized.

Show comment
Hide comment
@jcoglan

jcoglan Feb 28, 2012

Collaborator

Great, I'll close the issue then.

Collaborator

jcoglan commented Feb 28, 2012

Great, I'll close the issue then.

@digitalbias

This comment has been minimized.

Show comment
Hide comment
@digitalbias

digitalbias Jun 14, 2012

I still get this issue with faye-websocket-rails. Since there is no faye.ru involved I threw the following line into a rails initializer and it worked.

Faye::WebSocket.load_adapter 'thin'

I still get this issue with faye-websocket-rails. Since there is no faye.ru involved I threw the following line into a rails initializer and it worked.

Faye::WebSocket.load_adapter 'thin'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment