mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-06 15:23:12 +08:00
Ensured EntityManager is reopened by CloseDbConnectionMiddleware after an error closed it
This commit is contained in:
@@ -3,11 +3,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace Shlinkio\Shlink\Common\Middleware;
|
||||
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Throwable;
|
||||
|
||||
class CloseDbConnectionMiddleware implements MiddlewareInterface
|
||||
{
|
||||
@@ -23,6 +25,16 @@ class CloseDbConnectionMiddleware implements MiddlewareInterface
|
||||
{
|
||||
try {
|
||||
return $handler->handle($request);
|
||||
} catch (Throwable $e) {
|
||||
// FIXME Mega ugly hack to avoid a closed EntityManager to make shlink fail forever on swoole contexts
|
||||
// Should be fixed with request-shared EntityManagers, which is not supported by the ServiceManager
|
||||
if (! $this->em->isOpen()) {
|
||||
(function () {
|
||||
$this->closed = false;
|
||||
})->bindTo($this->em, EntityManager::class)();
|
||||
}
|
||||
|
||||
throw $e;
|
||||
} finally {
|
||||
$this->em->getConnection()->close();
|
||||
$this->em->clear();
|
||||
|
||||
Reference in New Issue
Block a user