cubiqsys-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-26 16:50 UTC
Weird "session-bug" when using multiple calls
Hi! Can someone understand why this happens? 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 <div id="startnav"> <script type="text/javascript" charset="utf-8"> new Ajax.Updater(''startnav'',''/start/printstart''); </script> </div> <%=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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 26 Feb 2008, at 16:50, cubiqsys-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Hi! > > Can someone understand why this happens? >Yes - I ran into this and wrote it up a while back: http://www.texperts.com/2007/05/01/race-conditions-in-rails-sessions-and-how-to-fix-them/ Fred> 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 > <div id="startnav"> > <script type="text/javascript" charset="utf-8"> > new Ajax.Updater(''startnav'',''/start/printstart''); > </script> > </div> > > <%=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? > > > --~--~---------~--~----~------------~-------~--~----~ > You received this message because you are subscribed to the Google > Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en > -~----------~----~----~----~------~----~------~--~--- >
cubiqsys-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Feb-27 09:21 UTC
Re: Weird "session-bug" when using multiple calls
Thanks a million! Nice to hear I''m not alone and just imagining things up :D Tried the plugin and it works great! Is this bug known to the RoR-developers btw? On 26 Feb, 18:04, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 26 Feb 2008, at 16:50, cubiq...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > > > Hi! > > > Can someone understand why this happens? > > Yes - I ran into this and wrote it up a while back:http://www.texperts.com/2007/05/01/race-conditions-in-rails-sessions-... > > Fred > > >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 > > <div id="startnav"> > > <script type="text/javascript" charset="utf-8"> > > new Ajax.Updater(''startnav'',''/start/printstart''); > > </script> > > </div> > > > <%=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? > > > > > > > smime.p7s > 5KHämta--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 27 Feb 2008, at 09:21, cubiqsys-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > Thanks a million! Nice to hear I''m not alone and just imagining things > up :D 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> On 26 Feb, 18:04, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> On 26 Feb 2008, at 16:50, cubiq...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: >> >> >> >>> Hi! >> >>> Can someone understand why this happens? >> >> Yes - I ran into this and wrote it up a while back:http://www.texperts.com/2007/05/01/race-conditions-in-rails-sessions- >> ... >> >> Fred >> >>> 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 >>> <div id="startnav"> >>> <script type="text/javascript" charset="utf-8"> >>> new Ajax.Updater(''startnav'',''/start/printstart''); >>> </script> >>> </div> >> >>> <%=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? >> >>>> >> >> >> smime.p7s >> 5KHämta > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---