Forum: Ruby on Rails Session being overwritten by different actions

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Frederick C. (Guest)
on 2007-02-14 17:31
Suppose you have a controller with 2 actions that look like this

  def long
    session[:foo] = "bar"
    sleep 15
    render :nothing => true

  def short
    session[:short] = 1
    render :nothing => true

  def status
    render :text => "session[:short] = #{session[:short]}"

This app is using the default Pstore sessions

I ran this app on a bunch of mongrels. In one browser window I kicked
off the long action, meanwhile in the second I ran the short action, and
then the status action to verify that the session did indeed contain the
value 1 for the key :short.

However once the long running action completes in then clobbers the hash
with its view of the world. session[:short] goes back to being empty.

Looking at the source it is clear why this happens: the first time the
session is accessed it is loaded from disk, and it is written back when
the action completes: it doesn't care if the session has changed in

Obviously we don't store anything vital in the session, but I was
wondering how other people cope with this.


Frederick C. (Guest)
on 2007-05-02 02:16
In case anyone digs up this thread, I implemented a solution to this
problem here:
This topic is locked and can not be replied to.