Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

JRuby - FlashHash not saving in session when storing ActiveRecord items

#3497

I switched to JRuby and started to experience this issue: I store a very lightweight activerecord object into the flash store sometimes (please hold back the flames, this bug shouldn't occur regardless) when reloading a form after a record fails validation. After the first ActiveRecord object is stored into the flash, I start to receive this error indefinitely (anytime I access the flash):

The error occurred while evaluating nil.[]
C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/flash.rb:111:in sweep'<br/> C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/flash.rb:110:ineach'
C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/flash.rb:110:in sweep'<br/> C:/jruby-1.4.0/lib/ruby/gems/1.8/gems/actionpack-2.3.4/lib/action_controller/flash.rb:164:inflash'

I looked at that line and it's accessing an instance variable of FlashHash named "@used", which stores all the used flash keys. That instance variable is nil on every request after storing an activerecord object into the flash hash. Now, it might be a session store issue as I am using the cookie store (I haven't tried other stores yet).

I'm thinking maybe JRuby and JRuby-OpenSSL is having problems dealing with serializing and deserializing activerecord objects in the cookie store? Anyone ever ran into this problem? If I delete my session cookie, the problem goes away until the next storage of an activerecord object into the flash.

I was very excited to commit to JRuby for true multithreading, but I will go back to trying to make 1.9 SVN work :-P

Thanks,
Jarred

Reported by Jarred Nicholls · November 19th, 2009 @ 05:44 PM

State: resolved
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Justin Coyne
    Justin Coyne

    Jarred. I'm using Jruby and have had problems with Cookie Store. We're having good luck with ActiveRecord Store and Servlet Session Store (if deploying in a servlet container)

    November 21st, 2009 @ 06:38 PM

  2. Jarred Nicholls
    Jarred Nicholls

    Thanks Justin for sharing.  I planned to setup Memcached anyways so maybe I wouldn't have an issue with a memcached session store.  I still went back to MRI for now...the amount of memory the JVM instance took up was too high for my current situation (even after adjusting heap and GC gen. sizes).

    November 21st, 2009 @ 09:16 PM

  3. Bryan Larsen
    Bryan Larsen

    We're running into the same problem here, and it affects both ActiveRecordStore and CookieStore. We can work around it with the attached patch. If we do that, we then run into this JRUBY bug: http://jira.codehaus.org/browse/JRUBY-3664

    December 21st, 2009 @ 08:21 PM

  4. Bryan Larsen
    Bryan Larsen

    Note that contrary to the title, we are not storing any ActiveRecord items in the session or in the FlashHash.

    December 21st, 2009 @ 08:23 PM

  5. Jarred Nicholls
    Jarred Nicholls

    Yeah, I actually did the same thing as the attached patch, but that opened up many more cans of worms. The fundamental issue is that the flash hash ceases to (de)serialize with certain content in it. I think sticking to primitive types is the only way to be safe.

    December 21st, 2009 @ 09:10 PM

  6. Emrys Ingersoll
    Emrys Ingersoll

    I'm also running into this problem using the JavaServletStore from the jruby-rack project as the session_store (Rails 2.3.5, jruby-rack-0.9.5, JRuby 1.4, Java 1.6.0_18 64bit on Linux 64bit). I get the same exception at same line (111) of action_controller/flash.rb

    February 15th, 2010 @ 10:12 PM

  7. Emrys Ingersoll
    Emrys Ingersoll

    I just built the current JRuby trunk as of commit 2770c7f5720aa23048fbef93b24140195be240ed and replaced JRuby 1.4 with the trunk version in my aforementioned environment and the problem appears to be solved.

    I would, tentatively, label this a JRuby issue and not Rails. Though, confirmation that this works for others would be good to have first.

    February 16th, 2010 @ 05:06 PM

  8. mtyaka
    mtyaka
    • Tag set to jruby

    This was a JRuby issue that was resolved in JRuby 1.5. It was caused by a bug in JRuby's Marshal.load.
    See tickets http://jira.codehaus.org/browse/JRUBY-4442 and http://jira.codehaus.org/browse/JRUBY-3530 for more information. This ticket can be closed.

    May 15th, 2010 @ 08:36 AM

  9. Rohit Arondekar
    Rohit Arondekar
    • State changed from new to resolved

    June 15th, 2010 @ 10:41 AM