ArgumentError: marshal data too short when loading session data
Posted on August 20, 2010 - Filed Under RubyOnRails
I was stuck for a while when application maintained by me have started to throw ArgumentError: marshal data too short errors in random places When user have encountered that problem then it was unable to use application at all.

Marshal CC http://www.flickr.com/photos/qmnonic/
Logs were showing that it happens when Rails was trying to create session object. Session store was in ActiveRecord and sessions table was not corrupted.
After watching that for a while it have shown that places in code were this exception was thrown were random but there was pattern. Page visited before was common in each case.
It have turned out that application was storing in session whole ActiveRecord object. Like:
session[:some_info] = @variable
And later we were trying to use that way:
@variable = Model.find session[:some_info]
Due to Rails magic AcitiveRecord’s find when provided with AR object will return that object (of course if is the same model). Code was working well (maybe not very effectively since You should avoid storing large objects in session) until object stored that way started to grow. Application was collecting some data and amount of data stored have grown to that point that after Marshal.dump size of string was more than 64 kB. And this is default size of text field used to store session data in MySQL.
When You try to store too much data in text field in MySQL, excessive data is being truncated, so Marshal.load throws that exception.
To have that error solved is enough to store just object id in session (session[:some_info] = @variable.id).
Popularity: 37% [?]
Hits for this post: 27242
Similar Posts
- Session store – don’t get trapped
- Skinny controller, fat model and Facebook
- Migrations headache
- Dont use sessions table in rails
- Interacting with Facebook without user
Comments
2 Responses to “ArgumentError: marshal data too short when loading session data”
-
The Ruby Reflector - ArgumentError on
June 29th, 2011 9:59
[...] ArgumentError: marshal data too short when loading session data By Witold Rugowski of NetManiac 10 months ago. [...]
-
planeta.rubyonrails.pl - Feed Directory on
July 8th, 2011 8:03
[...] ArgumentError: marshal data too short when loading session data 20 Aug 2010 22:24:27 GMT I was stuck for a while when application maintained by me have started to throw ArgumentError: marshal data too short errors in random places When user have encountered that problem then it was unable to use application at all. Logs were showing that it happens when Rails was trying to create session object. Session store was [...] show comments (0) | comment | denounce0up0down [...]
Leave a Reply


