Skip to content
This repository

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

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

3 participants

Mike Kelley James Coglan Dave Mitchell
Mike Kelley

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>'
James Coglan
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.

Mike Kelley

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
Mike Kelley

This does appear to resolve the issue, thanks!

James Coglan jcoglan closed this February 28, 2012
James Coglan
Collaborator

Great, I'll close the issue then.

Dave Mitchell

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
Something went wrong with that request. Please try again.