Improve handling of uncommitted DB txns with "uncaught" exceptions
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 27 Mar 2014 16:18:38 +0000 (12:18 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 27 Mar 2014 16:46:07 +0000 (12:46 -0400)
commitdc7d342d93b12c4990f147423082ed3481ed3358
treeb8031f0234380d2e34cf33d8818cbecd07aae97b
parent0966c801a4d4fa5c8f486d3b57e89a00afb757cf
Improve handling of uncommitted DB txns with "uncaught" exceptions

One of the causes (if not the cause) of bug 56269 is if something
manages to throw an exception that makes it to MediaWiki::run's
last-resort exception catcher while having an open database transaction:
the transaction never gets committed or rolled back, so it gets
implicitly rolled back and a warning is raised.

The API has the opposite problem in bug 63145: it catches the exception
but then does the normal DB shutdown which *commits* the transaction.
This is certainly the Wrong Thing to do.

Ideally, neither of these would ever happen because any code using
transactions would have its own try-catch that would catch any
exception, rollback the transaction, and then rethrow the exception. But
it happens anyway, so let's have both of these last-resort exception
handlers do the rollback, and also log the exception so the throwing
code has a better chance of being properly fixed.

Bug: 56269
Bug: 63145
Change-Id: I8f1da51187b281fe4afc0d5a0c49f5caf3612e92
includes/api/ApiMain.php
includes/db/Database.php
includes/db/LBFactory.php
includes/db/LoadBalancer.php
includes/exception/MWExceptionHandler.php