Strange Thread related errors

Iñaki Baz Castillo ibc at aliax.net
Thu Jan 7 14:08:38 EST 2010


El Jueves, 7 de Enero de 2010, Michael Guterl escribió:
> We currently disconnect from both databases in before_fork and
> re-establish the connection in after_fork.
> 
> Here's our unicorn config: http://gist.github.com/271449

Unfortunately I don't know very well ho ActiveRecords works but you could get 
into the same probem even if you disconnect the db in the case you are sharing 
the same ActiveRecord instance in all the workers.
This issue also ocurred to me using Sequel: I generated the DB instances in 
master process and stored them in an Array that later used in each worker so 
the fact is that I was sharing the same DB object in all the workers, so when 
they reconcet they are in fact using a single connection (or a single 
connection pool) for all the workers.

But I think that ActiveRecords works in a different way as you don't create a 
DB instance but instead use directly a class ("class MyModel < 
ActiveRecords").

 
> Maybe I should disable connection pooling?
 
This should not be the real cause of your problem (if the above is not 
happening to you). Unicorn workers are single thread which means you can use 
threads into them safely (except if those threads are, accidentally, shared by 
other processes).

I suggest the following: Tun the server and ensure you do enough requests so 
all the worker perform at least a DB query. And them check the current DB 
connection in your DB. If you dissable coonectino pooling you should see just 
N connections /being N the number of Unicorn workers).

-- 
Iñaki Baz Castillo <ibc at aliax.net>


More information about the mongrel-unicorn mailing list