"Marshal Data Too Short" error reading Session Data

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:inunmarshal’
[RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/session/
active_record_store.rb:122:in data' [RAILS_ROOT]/app/models/user.rb:113:inlogged_in_users’
[RAILS_ROOT]/app/models/user.rb:112:in each' [RAILS_ROOT]/app/models/user.rb:112:inlogged_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:insend’
[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:incall_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:incall’
[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:incall_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:incall_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:incall’
[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:incall_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:incall_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:incall’
[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:incall_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:incall’
[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:incall_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:incall_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:incall’
[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:inperform_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:inmeasure’
[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:inperform_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:inprocess_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:inprocess’
[RAILS_ROOT]/vendor/rails/actionpack/lib/action_controller/base.rb:
330:in process' [RAILS_ROOT]/vendor/rails/railties/lib/dispatcher.rb:41:indispatch’
/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:insynchronize’
/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:inprocess_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:inprocess_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:ininitialize’
/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:inrun’
/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:innew’
/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:inrun’
/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:inrun’
/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:inrun’
/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

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

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. [email protected]