petergoldstein / dalli

High performance memcached client for Ruby
MIT License
3.1k stars 450 forks source link

Cannot connect to server from delayed_job worker #105

Closed bglick closed 12 years ago

bglick commented 13 years ago

When running a job with delayed_job, I get errors when trying to access the Dalli Cache.

The Dalli cache is initialized in environment.rb with the following...

CACHE = Dalli::Client.new(['localhost:11211'], {:namespace=>my_namespace_method})

When the code executes CACHE.get 'my_key' in my rails app, everything runs fine.

When it runs in a delayed_job worker, it errors with No Server Available

Other info that might help:

I have confirmed that the memcached server is running and is accessible via telnet on localhost:11211 We're running Ruby 1.9.2 under rvm

Stack Trace: /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/dalli-1.0.5/lib/dalli/ring.rb:45:in server_for_key' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/dalli-1.0.5/lib/dalli/client.rb:239:inperform' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/dalli-1.0.5/lib/dalli/client.rb:126:in set' /home/brian/OpenChain/lib/open_chain/cache_wrapper.rb:8:inblock in set' /home/brian/OpenChain/lib/open_chain/cache_wrapper.rb:22:in error_wrap' /home/brian/OpenChain/lib/open_chain/cache_wrapper.rb:8:inset' /home/brian/OpenChain/app/models/master_setup.rb:35:in update_cache' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activesupport-3.0.8/lib/active_support/callbacks.rb:416:in_run_find_callbacks' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/base.rb:1457:in init_with' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/base.rb:915:ininstantiate' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/base.rb:473:in block in find_by_sql' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/base.rb:473:incollect!' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/base.rb:473:in find_by_sql' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/relation.rb:64:into_a' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/relation/finder_methods.rb:341:in find_first' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/relation/finder_methods.rb:122:infirst' /home/brian/.rvm/gems/ruby-1.9.2-p136/gems/activerecord-3.0.8/lib/active_record/base.rb:444:in first' /home/brian/OpenChain/app/models/master_setup.rb:26:ininit_base_setup' /home/brian/OpenChain/app/models/master_setup.rb:19:in get' /home/brian/OpenChain/app/views/open_mailer/send_generic_exception.text.erb:9:in_app_views_open_mailer_send_generic_exception_text_erb__24129118_108189210_831379336'

mperham commented 13 years ago

Did you ever resolve this? I don't use DJ so I'm not sure how it works (whether it forks workers possibly killing any open sockets, e.g.)

bglick commented 13 years ago

I did some digging under the hood on DJ, and it uses the Daemons gem to fork processes. My suspicion is that this is going to be something similar to the issues with Passenger that are noted in the Dalli documentation. We're going to play around next week with resetting the Dalli connection in DJ's before_start callback. *

Brian Glick* President Aspect 9 m: 215-821-6595 skype: brian-glick bglick@aspect9.com

On Fri, Jul 22, 2011 at 10:48 PM, mperham < reply@reply.github.com>wrote:

Did you ever resolve this? I don't use DJ so I'm not sure how it works (whether it forks workers possibly killing any open sockets, e.g.)

Reply to this email directly or view it on GitHub: https://github.com/mperham/dalli/issues/105#issuecomment-1636287

dignoe commented 12 years ago

Were you ever able to fix this? I'm having the same issue now.

bglick commented 12 years ago

@dignoe We never did solve it satisfactorily. We ended up writing a wrapper class for the cache that catches the exception and reloads a new cache object.