mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge pull request #9213 from appwrite/fix-dead-connections
Fix dead connections
This commit is contained in:
@@ -5,6 +5,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
|
||||
use Appwrite\Utopia\Request;
|
||||
use Appwrite\Utopia\Response;
|
||||
use Swoole\Constant;
|
||||
use Swoole\Database\DetectsLostConnections;
|
||||
use Swoole\Http\Request as SwooleRequest;
|
||||
use Swoole\Http\Response as SwooleResponse;
|
||||
use Swoole\Http\Server;
|
||||
@@ -17,6 +18,7 @@ use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\DateTime;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Exception as DatabaseException;
|
||||
use Utopia\Database\Exception\Duplicate;
|
||||
use Utopia\Database\Helpers\ID;
|
||||
use Utopia\Database\Helpers\Permission;
|
||||
@@ -346,6 +348,15 @@ $http->on(Constant::EVENT_REQUEST, function (SwooleRequest $swooleRequest, Swool
|
||||
|
||||
$app->run($request, $response);
|
||||
} catch (\Throwable $th) {
|
||||
if (
|
||||
($th instanceof PDOException || $th instanceof DatabaseException)
|
||||
&& DetectsLostConnections::causedByLostConnection($th)
|
||||
) {
|
||||
// Mark connection as unhealthy so it will be recycled on next reclaim.
|
||||
$connectionForProject = $app->getResource('connectionForProject');
|
||||
$connectionForProject->setHealthy(false);
|
||||
}
|
||||
|
||||
$version = System::getEnv('_APP_VERSION', 'UNKNOWN');
|
||||
|
||||
$logger = $app->getResource("logger");
|
||||
|
||||
Reference in New Issue
Block a user