Every repository with this icon (
Every repository with this icon (
| Description: | Rack::Session, Rack::Cache and cache Redis stores for Ruby web frameworks edit |
-
undefined method `retrieve_session' for nil:NilClass
0 comments Created 4 months ago by TalleyranHi
I try use this gem with my merb app, but got:
merb : worker (port 4000) ~ Could not retrieve session from Merb::RedisSession: undefined method `retrieve_session' for nil:NilClass
when stored data.
merb-core 1.1Comments
-
I encountered a 500 error when call reset_session in SessionController::logout.
It may not be a redis-store issue due to this issue occurs in nofxx-tokyo_store too. I digged a little deeper with the rails and rack session process but didn't got a clear clue, so I'm report here, hope can got your help.Comments
sure, here is the stack-trace: http://gist.github.com/230548
I noticed the session_id pass to Rack::Session::Redis#set_session was nil
If we regenerate_sid in set_session
40 def set_session(env, session_id, new_session, options) 41 @mutex.lock if env['rack.multithread'] 42 session = @pool.get(session_id) rescue {} 43 session_id = generate_sid if session_id.nil? 44 if options[:renew] or options[:drop]logout will be smooth as normal, but there is another problem, the old session will not deleted.
I got it work.
It end up to set :renew and :drop to options:
# reset_session request.session_options[:renew] = true request.session_options[:drop] = trueI not confident is this gonna broken in the future due to the correctly API seems to be request.reset_session, I also lookup into Rack::Session::Memcache, Rack::Session::Tyrant, the implementation seems no different to me.
Anyway, as long as it works, I'm happy.
tnx for your help and your great work.
-
When I use this session store in Rails, I'm seeing that the flash is getting stuck over more than just the next request. Been trying to track down the code but can't quite figure it out.
Comments
I will try to investigate, are you sure this error only affects the redis-store? Did you tried to switch to another Rails bundled store: ie. file-system, or memcached.
I switched to my own implementation (at a higher level in the code base, similar to the built in memcache_store) and the flash wasn't sticky.
I'll try to see if I can't make a simple Rails app that duplicates this...
I also am experiencing this issue after switching my sessions to redis-store.
This probably isn't the correct way to fix the issue, however, it does work and may shed some more light on why this is happening. I think the problem is that new['flash'] != old['flash'] isn't comparing correctly because of the way flash (in Rails) marks keys as dirty once they are used.
lib/rack/session/redis.rb: line 62: def merge_sessions(sid, old, new, cur=nil) cur ||= {} unless Hash === old and Hash === new warn 'Bad old or new sessions provided.' return cur end delete = old.keys - new.keys warn "//@#{sid}: dropping #{delete*','}" if $DEBUG and not delete.empty? delete.each{|k| cur.delete k } update = new.keys.select{|k| new[k] != old[k] } warn "//@#{sid}: updating #{update*','}" if $DEBUG and not update.empty? update.each{|k| cur[k] = new[k] } # ===> BEGIN fix cur['flash'] = old['flash'] unless old['flash'].nil? # ===> END fix cur endFor Rails users here is a quick monkeypatch that should get flash working:
in config/initializers/session_store.rb add this to the bottom: module Rack module Session class Redis private; def merge_sessions_with_flash_fix(sid, old, new, cur=nil) cur = merge_sessions_without_flash_fix(sid, old, new, cur) cur['flash'] = old['flash'] unless old['flash'].nil? cur end alias_method_chain :merge_sessions, :flash_fix end end endSorry for the delay, I'm digging into the problem, and the same issue seems to affect
Rack::Session::Memcache.When the redirect is being performed, the
newobject still has theflashkey, so the problem isn't in themerge_sessionsalgorithm.The problem is in
ActionController::Flash::FlashHash#sweep, when the session store is set onCookieStore(default), it properly handle the@usedhash, so the flash keys are deleted after the first use.@used[:notice] # => false on the first request, then true on subsequent (CookieStore)@used[:notice] # => It's always false with Redis/Memcache storeAs you can see, this prevent the deletion of the key. I'm looking for the root cause and figuring out how to patch it.











