Re: [dancer-users] Dancer app in production on Starman : Dancer::Plugin::Database Child process cannot use database handle created in parent
Without any actual internal knowledge, my one guess would be forking. If you make a database connection into a variable (e.g. database, or $dbh) then you fork, then you can no longer access that connection. There is a way to share a pool of connections (in apache aka Apache::DBI) or I used to use PerChild directive on Apache to make a connection. Now it should all be handled, but maybe it isn’t? Scott On 11 Feb 2014, at 9:23 am, Anthony Milan <anthony.milan@laposte.net> wrote:
Le 10/02/2014 22:57, Anthony Milan a écrit :
Hi,
I tried to deploy my little app with Starman: plackup -E deployment -s Starman -p 5001 --workers=2 -a bin/app.pl
I had this error: Child process cannot use database handle created in parent
I used Dancer::Plugin::Database to manage database
In this thread: http://lists.preshweb.co.uk/pipermail/dancer-users/2011-July/001681.html I read that Dancer::Plugin::Database ensure that handles are not shared between processes/threads.
Most probably, I do something wrong :(
I googled around starman and DBI and I execute Starman without plackup.
starman -p 5000 --workers=2 -a ../bin/app.pl
It seems to work. Any idea?
Thanks -- Anthony Milan _______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Le 10/02/2014 23:29, Scott Penrose a écrit :
Without any actual internal knowledge, my one guess would be forking.
Yes.
If you make a database connection into a variable (e.g. database, or $dbh) then you fork, then you can no longer access that connection.
There is a way to share a pool of connections (in apache aka Apache::DBI) or I used to use PerChild directive on Apache to make a connection.
Now it should all be handled, but maybe it isn’t?
Ok. I changed from: use Dancer::Plugin::Database; my $dbh = database('db1'); to get '/something/:id' => sub { my $dbh = database('db1'); } Thanks, -- Anthony Milan
On Tue, 11 Feb 2014 00:29:24 +0100 Anthony Milan <anthony.milan@laposte.net> wrote:
Le 10/02/2014 23:29, Scott Penrose a écrit :
Without any actual internal knowledge, my one guess would be forking.
Yes.
If you make a database connection into a variable (e.g. database, or $dbh) then you fork, then you can no longer access that connection. [...] Now it should all be handled, but maybe it isn’t?
Ok. I changed from:
use Dancer::Plugin::Database; my $dbh = database('db1');
to
get '/something/:id' => sub { my $dbh = database('db1');
}
Bingo. Dancer::Plugin::Database caches the handles it gives you, so you can call database() repeatedly and get the same handle back, but takes care that the handles it will give you from the cache are the ones for the current process ID / thread - so if you've forked, it won't accidentally give you one from the parent. If you've got one before a fork and hung on to it yourself, though, it can't help you there :) -- David Precious ("bigpresh") <davidp@preshweb.co.uk> http://www.preshweb.co.uk/ www.preshweb.co.uk/twitter www.preshweb.co.uk/linkedin www.preshweb.co.uk/facebook www.preshweb.co.uk/cpan www.preshweb.co.uk/github
participants (3)
-
Anthony Milan -
David Precious -
Scott Penrose