Badai Aqrandista wrote:
> I am having problem with database connection for the session locks
> dropping intermittently...
> DBD::mysql::st execute failed: Lost connection to MySQL server...
...
> {
>     my $main_dbh = MyApp::DB->_connect_db(db_name => 'myapp');
>     sub __admin_mason_handler
>     {
>         return HTML::Mason::ApacheHandler->new(
...
>             request_class => 'MasonX::Request::WithApacheSession',
...
>             session_handle => $main_dbh,
>             session_lock_handle => $main_dbh,
>         );
>     }
> }
>
> sub handler($$)
> {
>     my $class = shift;
>     my $r = Apache::Request->new(shift);
>     return __admin_mason_handler()->handle_request($r);
> }
>
> I use Apache::DBI in startup.pl to have persistent connection.
The short answer: you're using same handle for session and session_lock.
This should be the source of your error, with or without Apache::DBI.

I've seen this (almost?) always happening in this scenario
(Apache::Session initialized using a DB handle — same for sessions and
locks). So, either use DSN descriptors (letting Apache::Session take
care of dbh) or upgrade your MyApp::DB->_connect_db method to allow
using private attributes (then being able to use separate handles for
sessions/locks).

Hmm... After I changed the code to this (move the $main_dbh creation into the mason handler), the error stops coming... If the error comes again I'll create special database handle for session lock...

{
   sub __admin_mason_handler
   {
       my $main_dbh = MyApp::DB->_connect_db(db_name => 'myapp');

       return HTML::Mason::ApacheHandler->new(
           ...
           request_class => 'MasonX::Request::WithApacheSession',
           ...
           session_handle => $main_dbh,
           session_lock_handle => $main_dbh,
       );
   }
}

On a side note, you have a huge performance penalty by instantiating
your handler with each request (BTW, _avoid_ Apache::Request->new,
always use Apache::Request->instance) — something like going from
mod_perl to CGI back again :(

Thanks for pointing this to me.

---
Badai Aqrandista
Cheepy (?)

_________________________________________________________________
New year, new job – there's more than 100,00 jobs at SEEK http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek%2Ecom%2Eau&_t=752315885&_r=Jan05_tagline&_m=EXT



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Mason-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mason-users

Reply via email to