I’ve discovered something really weird in rails 1.2.3 (It could be
fixed in 2.0? but I don’t know).
Recently I started getting the error “Mysql::Error: Lost connection to
MySQL server during query” in my application. It seemed like it had
popped up almost without relation to anything. There was a page in the
RoR wiki with possible solutions but none of them had worked (http://
wiki.rubyonrails.org/rails/pages/Mysql+Connection+Problems), it was
driving me crazy!
Anyway, one day the error message changed, and turned into something
like “data too long for field: sessions.data”. Now this message was a
bit more obvious what was goin on! I was storing too much in my
session! And I hadn’t realised that there was a limit to that…
Specifically what I was doing was storing my cart in the session, and
this was overloading the db field sometimes, but not all the time, and
only after I started playing with my site a lot.
I fixed the cart problem by turning it into an active record object,
and just storing the id in session. BAM! there were no more DB errors!
magic! no more lost connections, nada.
Until… I found another place I was storing objects in session - In
my wizards. Sometimes, if I am creating a particularly complex object,
I use a ‘wizard’ to do it. I do this by storing my object in session,
and slowly build onto it with each step/page. I’m trying to figure out
some way to do this without storing the whole object in session. Any