[jifty-devel] Jifty server stuck

Andrew Hanenkamp sterling at hanenkamp.com
Thu Jan 24 12:35:38 EST 2008

On 1/22/08, Jesse Vincent <jesse at bestpractical.com> wrote:
> It _should_ be possible to sink that down into Jifty::DBI, possibly down
> as far as ::Handle->simple_query. (Say, trap a failure and retry if you
> get a not-connected error?) That way you don't get the overhead of a
> ping before each statement.
> -j

Added to Jifty::DBI. Hopefully this will resolve some issues I'm having with
sessions failing to load properly (which happens before the before rules).

And an FYI regarding some other things I've learned through this: As I was
digging around, I found a better way to do this by implementing the
"before_request" trigger. This should not be necessary on the very latest
Jifty::DBI, but could be done from the main application package as:

package MyJiftyApp;

sub start {
  Jifty->handler->add_trigger( before_request => sub {
Jifty->handle->connect } );


That would be the best way to implement this since session loading depends
on the database and happens before the first before rule is executed.

Again, this shouldn't be necessary if you use the very latest Jifty::DBI
trunk, but in case you can't yet this is about as good as it gets. It will
not help you if your database connection craps out in the middle of a
request, which should be almost entirely solved by the Jifty::DBI patch,
but, hopefully, that is very rare.

In addition to this, MySQL users may also want to setup auto-reconnection.
In that case, you might re-implement the above as:

sub start {
  Jifty->handle->dbh->{mysq_auto_reconnect} = 1;

Though, you should be aware of these caveats described in the driver docs:

Setting mysql_auto_reconnect to on is not advised if 'lock tables' is used
> because if DBD::mysql reconnect to mysql all table locks will be lost. This
> attribute is ignored when AutoCommit is turned off, and when AutoCommit is
> turned off, DBD::mysql will not automatically reconnect to the server.

This does highlight a potential flaw in the reconnect implementation in
Jifty::DBI since it won't attempt to re-acquire any locks or fail during
reconnection if your application is in the middle of a non-autocommit
transaction. This requires further consideration.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jifty.org/pipermail/jifty-devel/attachments/20080124/064dbb77/attachment-0008.htm 

More information about the jifty-devel mailing list