You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was developing a Rails app that switches the session store to redis and accidentally set expire_after: nil. I found a strange behavior with that setting and I'd like to report it.
redis-rack stores session keys in cookies and session values in redis.
expire_after: nil setting makes lifetime mismatch
Session key is saved as "session cookie" (expires when browser session ends)
Session value is saved in redis without ttl
With expire_after: nil setting, client's session key is sometime expired, but session value is not expired.
So the redis will accumulate more and more non-volatile keys.
Of course, I am aware that using the redis session store with expire_after: nil is not a good idea. However, the current behavior is confused for me.
@hogelog The behavior of :expire_after isn't defined by this gem, it's ultimately up to rack-session to define how this should work. The redis-store gem is solely responsible for passing options down to Redis properly.
I can see that on line 14, we're calling #to_i on the TTL, which given all of the options for expiry being nil, should result in setting the Redis TTL to 0. This effectively gives the keys no expiry at all.
The closest I'd like to get in this gem is option 3, but if you set expire_after: nil the gem should just throw an error. I can't think of a good reason why you would want to set a default session expiration to nil, and the other two solutions you describe are both just best guesses at the intention of the developer, which I feel would be too error-prone and could result in a lot of unexpected behavior, especially for any "power-users" of this gem. In a former project that I helped build, we defaulted the session expiry time so that it would never be nil, because we ran into similar problems: https://github.com/workarea-commerce/workarea/blob/master/core/config/initializers/22_session_store.rb#L10, so I would vote for preventing this kind of behavior at all since it seems to be a state you don't ever want to end up in.
I can't think of a good reason why you would want to set a default session expiration to nil
Yes. I had a little accident on my application with the redis-rack gem this expire_after: nil setting's behavior. But my application's expire_after: nil setting is accidently mixed in. So your idea that "if you set expire_after: nil the gem should just throw an error" is sounds good for me.
@hogelog yeah I can imagine something like setting that expire after to an env var that doesn't exist would trigger this behavior. Looking into it now to see if this would be safe.
I was developing a Rails app that switches the session store to redis and accidentally set
expire_after: nil
. I found a strange behavior with that setting and I'd like to report it.expire_after: nil
setting makes lifetime mismatchWith
expire_after: nil
setting, client's session key is sometime expired, but session value is not expired.So the redis will accumulate more and more non-volatile keys.
Of course, I am aware that using the redis session store with
expire_after: nil
is not a good idea. However, the current behavior is confused for me.Reproduction
I checked with the following code.
Procedure
ruby app.rb
What to do
How the
expire_after: nil
setting should work.1. Match the session key deadline
Storing session with
expire_after: nil
in the session cookie setting is rack's default behavior.This method seems the least confusing.
2. Match the session value expiration date
There may be some confusion because the default session behavior of rack.
However, it may be consistent within redis-rack.
3. Nothing to do
As I described earlier, I think it is a confusing and not happy behavior.
The text was updated successfully, but these errors were encountered: