Fix error transaction handling when creating a server.
There is a bug in the design of the application that affects users who encounter an exception under certain code pathways who are using the database to maintain their sessions. What is happening is that a transaction is started, and I made the mistake of just assuming it would auto-rollback once the exception was caught by the handler. This is technically true, since once the request terminates the transaction is discarded by the SQL server. However, this also means that the session data set on that request would not be persisted as it runs in a middleware termination function, after the transaction is started. Theoretically this would also affect any other terminable middleware as well, but the session is the only one I can think of right now Co-Authored-By: Oreo Oreoniv <zkoz210@users.noreply.github.com> Co-Authored-By: Stepan Fedotov <trixterthetux@users.noreply.github.com>
This commit is contained in:
parent
ca193deee4
commit
114afb8646
2 changed files with 18 additions and 0 deletions
|
@ -6,6 +6,7 @@ use Exception;
|
|||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
@ -137,6 +138,21 @@ class Handler extends ExceptionHandler
|
|||
*/
|
||||
public function render($request, Exception $exception)
|
||||
{
|
||||
$connections = Container::getInstance()->make(Connection::class);
|
||||
|
||||
// If we are currently wrapped up inside a transaction, we will roll all the way
|
||||
// back to the beginning. This needs to happen, otherwise session data does not
|
||||
// get properly persisted.
|
||||
//
|
||||
// This is kind of a hack, and ideally things like this should be handled as
|
||||
// much as possible at the code level, but there are a lot of spots that do a
|
||||
// ton of actions and were written before this bug discovery was made.
|
||||
//
|
||||
// @see https://github.com/pterodactyl/panel/pull/1468
|
||||
if ($connections->transactionLevel()) {
|
||||
$connections->rollBack(0);
|
||||
}
|
||||
|
||||
return parent::render($request, $exception);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue