Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

Comments

@codezomb
Copy link

@codezomb codezomb commented Feb 28, 2012

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.

Copy link
Collaborator

@jcoglan 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.

Copy link
Author

@codezomb codezomb commented 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
@codezomb

This comment has been minimized.

Copy link
Author

@codezomb codezomb commented Feb 28, 2012

This does appear to resolve the issue, thanks!

@jcoglan

This comment has been minimized.

Copy link
Collaborator

@jcoglan jcoglan commented Feb 28, 2012

Great, I'll close the issue then.

@digitalbias

This comment has been minimized.

Copy link

@digitalbias digitalbias commented 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'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.