# "Marshal Data Too Short" error reading Session Data

**URL:** <https://www.ruby-forum.com/t/marshal-data-too-short-error-reading-session-data/142066>\
**Category:** Rails\
**Created:** [July 3, 2008, 4:33am UTC](https://www.ruby-forum.com/t/marshal-data-too-short-error-reading-session-data/142066 "2008-07-03T04:33:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [July 3, 2008, 4:33am UTC](https://www.ruby-forum.com/t/marshal-data-too-short-error-reading-session-data/142066/1 "2008-07-03T04:33:08Z")

</div>

Hi all,

I am experiencing an error when reading session data. The problem is  
that it doesn’t happen all the time, in most cases it doesn’t occur.  
But it does so enough to start to become annoying.

It happens when trying to read a session record’s data property. The  
session store is in the Postgres database (version 8.2) and the  
sessions.data column is of type text (so theoretically unlimited in  
size).

Now I believe the error can happen in relation to data being truncated  
and then when it’s marshalled back it’s then found to be too short.  
But with the sessions.data column being of type text and the session  
information that is being stored not being of any great size (not even  
close), I’m not sure what the problem could be.

This is the snippet of code where the error occurs:

session\_store = CGI::Session::ActiveRecordStore::Session  
sessions = session\_store.find(:all, :conditions =\> [“updated\_at \> ?”,  
1.hour.ago], :order =\> “updated\_at”)  
user\_session\_data = {}

sessions.each do |sess|  
next unless sess.data && sess.data.has\_key?(:user\_id)  
user\_session\_data[sess.data[:user\_id]] = sess.updated\_at  
end

The exception happens on this call: next unless sess.data. In the call  
to sess.data.

I’ve included the trace below for reference.

Has anyone else experience this problem? Any help would be greatly  
appreciated.

Cheers,  
Diego

* * *

[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/session/  
active\_record\_store.rb:84:in `load' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/session/ active_record_store.rb:84:in`unmarshal’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/session/  
active\_record\_store.rb:122:in `data' [RAILS_ROOT]/app/models/user.rb:113:in`logged\_in\_users’  
[RAILS\_ROOT]/app/models/user.rb:112:in `each' [RAILS_ROOT]/app/models/user.rb:112:in`logged\_in\_users’  
[RAILS\_ROOT]/app/controllers/users\_controller.rb:48:in  
`logged_in_users' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/base.rb: 1095:in`send’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/base.rb:  
1095:in `perform_action_without_filters' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 632:in`call\_filter’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
638:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 438:in`call’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
637:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 638:in`call\_filter’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
438:in `call' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 637:in`call\_filter’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
638:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 438:in`call’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
637:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 638:in`call\_filter’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
438:in `call' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 637:in`call\_filter’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
638:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 438:in`call’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
637:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 634:in`call\_filter’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
638:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 438:in`call’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
637:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 638:in`call\_filter’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
449:in `call' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 637:in`call\_filter’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
638:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 449:in`call’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
637:in `call_filter' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/filters.rb: 619:in`perform\_action\_without\_benchmark’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' /usr/local/lib/ruby/1.8/benchmark.rb:293:in`measure’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/rescue.rb: 83:in`perform\_action’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/base.rb:  
430:in `send' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/base.rb: 430:in`process\_without\_filters’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/filters.rb:  
624:in `process_without_session_management_support' [RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/ session_management.rb:114:in`process’  
[RAILS\_ROOT]/vendor/rails/actionpack/lib/action\_controller/base.rb:  
330:in `process' [RAILS_ROOT]/vendor/rails/railties/lib/dispatcher.rb:41:in`dispatch’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/  
rails.rb:84:in `process' /usr/local/lib/ruby/1.8/sync.rb:229:in`synchronize’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/  
rails.rb:83:in `process' /usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb: 580:in`process\_client’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:  
579:in `each' /usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb: 579:in`process\_client’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:  
686:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb: 686:in`initialize’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:  
686:in `new' /usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb: 686:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:  
673:in `initialize' /usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb: 673:in`new’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:  
673:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/ configurator.rb:267:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/  
configurator.rb:266:in `each' /usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/ configurator.rb:266:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel\_rails:  
127:in `run' /usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/ command.rb:211:in`run’  
/usr/local/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel\_rails:  
231  
/usr/local/bin/mongrel\_rails:16:in `load’  
/usr/local/bin/mongrel\_rails:16

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [July 3, 2008, 10:56am UTC](https://www.ruby-forum.com/t/marshal-data-too-short-error-reading-session-data/142066/2 "2008-07-03T10:56:50Z")

</div>

On 3 Jul 2008, at 03:32, Diego wrote:

> Hi all,
> 
> I am experiencing an error when reading session data. The problem is  
> that it doesn’t happen all the time, in most cases it doesn’t occur.  
> But it does so enough to start to become annoying.

I don’t know postgresql but have you tried using a blob column (or  
whatever the postgres equivalent is)? Most databases will truncate/  
ignore text data which contains an illegal character sequence, null  
bytes and stuff like that which your marshalled session data could  
easily contain.

Fred

---

<div class="post-metadata">

**Author:** ![Diego](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f04885/32.png) [@Diego](https://www.ruby-forum.com/u/Diego)\
**Post date:** [July 3, 2008, 12:43pm UTC](https://www.ruby-forum.com/t/marshal-data-too-short-error-reading-session-data/142066/3 "2008-07-03T12:43:00Z")

</div>

Hi Fred,

Thanks for taking the time to reply. Appreciate it. I’ll look in to  
trying a blob field to see if it stops this problem from occurring.

Cheers,  
Diego

On Jul 3, 6:56 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
