# Weird "session-bug" when using multiple calls

**URL:** <https://www.ruby-forum.com/t/weird-session-bug-when-using-multiple-calls/130241>\
**Category:** Rails\
**Created:** [February 26, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/weird-session-bug-when-using-multiple-calls/130241 "2008-02-26T17:51:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 26, 2008, 5:51pm UTC](https://www.ruby-forum.com/t/weird-session-bug-when-using-multiple-calls/130241/1 "2008-02-26T17:51:17Z")

</div>

Hi!

Can someone understand why this happens?

[http://pastebin.com/mde5f1b7](http://pastebin.com/mde5f1b7)

* * *

#controller  
class StartController \< ApplicationController  
append\_before\_filter :get\_page\_settings  
def get\_page\_settings()  
session[:testlist] ||= Hash.new  
end

```
    def fillsession
            render :update do |page|
                    page.alert(session[:testlist].inspect)
                    session[:testlist]["ken"] = "man"
                    session[:testlist]["barbie"] = "woman"
                    page.alert(session[:testlist].inspect)
            end
    end

    def printstart
            render :partial => "startnav"
    end

```

end

#index.rhtml

\<%=link\_to\_remote(“Fill session”, :url =\> { :action =\> “fillsession” })  
%\>

#\_startnav.rhtml  
\<% sleep(5); %\>  
Hello World!

#1. I go to start/index  
#2. The printstart trigger but starts to sleep  
#3. Meanwhile I push the “Fill session”-link, which first alerts an  
empty Hash, then {“barbie”=\>“woman”, “ken”=\>“man”}  
#4. The sleep is over and Hello World! displays  
#5. I push the “Fill session”-link again. It should now alert  
{“barbie”=\>“woman”, “ken”=\>“man”} two times, but instead the session  
is empty and alerts an empty hash the first time ☹ Why?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2008, 10:21am UTC](https://www.ruby-forum.com/t/weird-session-bug-when-using-multiple-calls/130241/2 "2008-02-27T10:21:39Z")

</div>

Thanks a million! Nice to hear I’m not alone and just imagining things  
up 😃 Tried the plugin and it works great!

Is this bug known to the RoR-developers btw?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 26, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/weird-session-bug-when-using-multiple-calls/130241/3 "2008-02-26T18:05:29Z")

</div>

On 26 Feb 2008, at 16:50, removed\_email\_address@domain.invalid wrote:

> Hi!
> 
> Can someone understand why this happens?

Yes - I ran into this and wrote it up a while back:

> **[钛刻专家——官网](https://www.texperts.com/2007/05/01/race-conditions-in-rails-sessions-and-how-to-fix-them/)**
>
> 钛刻专家致力于打造一个全球专家在线服务平台，为机构和个人对接高水平行业专家，为机构提供更系统性的线下定制专家服务。

Fred

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 27, 2008, 10:34am UTC](https://www.ruby-forum.com/t/weird-session-bug-when-using-multiple-calls/130241/4 "2008-02-27T10:34:40Z")

</div>

On 27 Feb 2008, at 09:21, removed\_email\_address@domain.invalid wrote:

> Thanks a million! Nice to hear I’m not alone and just imagining things  
> up 😃 Tried the plugin and it works great!
> 
> Is this bug known to the RoR-developers btw?

I did raise this on trac a while back, but the overall response was  
that it wasn’t enough of an issue for most people (and with the  
cookiestore it’s not even possible to do this, since you can’t reload  
the session data).

Fred
