Wes Gamble
2006-Oct-11 20:38 UTC
Marshal Data too short error with ActiveRecord sess. storage
I''m seeing a "marshal data too short" error with an ActiveRecord store for my session data. Other posts say that this happens when the size of the session data exceeds the size of the "data" column in the sessions table. But my "data" column is a TEXT field so it seems unlikely that I could have blown it out. Has anyone else seen "marshal data too short" with a database session data store and if so, figured out a clever way around it? Thanks, Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2006-Oct-11 20:41 UTC
Re: Marshal Data too short error with ActiveRecord sess. sto
The sessions.data column is a SQL Server "text" column, which should be able to hold up to 2G (I think). I am accessing the DB via ODBC and I''m thinking perhaps that''s the issue? Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
David Felstead
2006-Oct-12 05:36 UTC
Re: Marshal Data too short error with ActiveRecord sess. storage
I''ve run into this before, not with sessions, but with some other data stored in a table. The issue, from memory, was something to do with this line in my.cnf: [mysqld] max_allowed_packet = 1M Which basically means (IIRC) that the longest query you may send to the server is 1MB. This means that if your marhalled session data is bigger than that (plus the overhead of the statement) then you will get a "Packet too large" error and AR''s connection will be severed. I can''t remeber if this is the exact reason the problem occurred, but upping the value did fix it. However, if you''re storing more than a megabyte in session then you probably have bigger problems than worrying about truncated session data - namely the huge overhead of continuously reading and updating this data with EVERY SINGLE REQUEST. Once you get up around a large number of requests, that''s a lot of data being piped around, which probably ain''t a good thing. I''d guess you''re probably storing AR objects in session, which is fine, but make sure that their associated objects don''t get marshalled as well, otherwise you might end up with a massive association tree being stored as well. Either just store the ID of the object in question, or modify your AR classes so the associated classes aren''t marshalled - I did this by adding the following mixin to my models to make sure only the "attributes" hash was marshalled for the ones I stored in session: module OnlyMarshalAttributes def marshal_dump @attributes end def marshal_load(data) @attributes = data end end class MyModel < ActiveRecord::Base # Make sure only local data gets marshalled include OnlyMarshalAttributes has_and_belongs_to :other_models has_many :different_things end There may be further caveats to marshalling/unmarshalling only @attributes (and accessing it directly is bad practice, but hey, it gets the job done in this case) so be aware that it may not be fully future proof. For now though, it seems to work pretty well. Hope that helps! -David Felstead On 10/12/06, Wes Gamble <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I''m seeing a "marshal data too short" error with an ActiveRecord store > for my session data. > > Other posts say that this happens when the size of the session data > exceeds the size of the "data" column in the sessions table. But my > "data" column is a TEXT field so it seems unlikely that I could have > blown it out. > > Has anyone else seen "marshal data too short" with a database session > data store and if so, figured out a clever way around it? > > Thanks, > Wes > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2006-Oct-12 14:24 UTC
Re: Marshal Data too short error with ActiveRecord sess. sto
David, Thanks for the comprehensive response. I _am_ storing AR objects in session but only temporarily before I actually want to persist them to the database (then I nil them out in the session). I will dig deeper into the attributes marshaling/unmarshaling you mention. Thanks, Wes -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2006-Oct-18 16:37 UTC
Re: Marshal Data too short error with ActiveRecord sess. sto
Does anyone know how to figure out the size of a text column in SQL Server? Or, better yet, how to figure out what''s in the serialized session data? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Wes Gamble
2006-Oct-23 17:39 UTC
Re: Marshal Data too short error with ActiveRecord sess. sto
Wes Gamble wrote:> Does anyone know how to figure out the size of a text column in SQL > Server?SELECT datalength(data) FROM sessions; -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---