"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

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