Active_record + threads


#1

I’m having problems with active_record within threads

I have some code that works alone, but if I insert it into a thread
with:

threads = []
for x in 1…5 do
threads << Thread.new do
team = Team.find(2)
end
end

threads.each do |t|
t.join
end

That code fails with:

/usr/local/lib/site_ruby/1.8/active_record/connection_adapters/abstract_adapter.rb:147:in
log': Mysql::Error: Lost connection to MySQL server during query: SELECT * FROMteamsWHERE (teams.id= 2) (ActiveRecord::StatementInvalid) from simm.rb:311:injoin’
from simm.rb:311
from simm.rb:310:in `each’
from simm.rb:310

Seems the connection goes away inside threads, isn’t it?
It works without threads…