From a2315821cabcc434ebb723bf0c9357fcd9c8f989 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 15 Sep 2021 15:22:50 +0200 Subject: [PATCH 1/3] fix(realtime): memory leak #2 --- app/realtime.php | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index 40537ea61..76b5ca350 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -102,9 +102,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId) /** * Save current connections to the Database every 5 seconds. */ - Timer::tick(5000, function () use ($stats, $getConsoleDb, $containerId, &$documentId) { - [$consoleDb, $returnConsoleDb] = call_user_func($getConsoleDb); - + Timer::tick(100, function () use ($stats, $getConsoleDb, $containerId, &$documentId) { foreach ($stats as $projectId => $value) { if (empty($value['connections']) && empty($value['messages'])) { continue; @@ -129,8 +127,6 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId) if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') { $usage->trigger(); } - - unset($usage, $connections, $messages); } $payload = []; foreach ($stats as $projectId => $value) { @@ -141,19 +137,21 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId) if (empty($payload)) { return; } - $document = [ - '$id' => $documentId, - '$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS, - '$permissions' => [ - 'read' => ['*'], - 'write' => ['*'], - ], - 'container' => $containerId, - 'timestamp' => time(), - 'value' => json_encode($payload) - ]; + try { - $document = $consoleDb->updateDocument($document); + [$consoleDb, $returnConsoleDb] = call_user_func($getConsoleDb); + + $consoleDb->updateDocument([ + '$id' => $documentId, + '$collection' => Database::SYSTEM_COLLECTION_CONNECTIONS, + '$permissions' => [ + 'read' => ['*'], + 'write' => ['*'], + ], + 'container' => $containerId, + 'timestamp' => time(), + 'value' => json_encode($payload) + ]); } catch (\Throwable $th) { Console::error('[Error] Type: ' . get_class($th)); Console::error('[Error] Message: ' . $th->getMessage()); @@ -171,7 +169,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, $attempts = 0; $start = time(); - Timer::tick(5000, function () use ($server, $register, $realtime, $stats) { + Timer::tick(100, function () use ($server, $register, $realtime, $stats) { /** * Sending current connections to project channels on the console project every 5 seconds. */ From 7ef31e6fbeaf951bf24de94d08f9d409224c9860 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 15 Sep 2021 15:28:21 +0200 Subject: [PATCH 2/3] revert leftover --- app/realtime.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/realtime.php b/app/realtime.php index 76b5ca350..70eacc0d4 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -102,7 +102,7 @@ $server->onStart(function () use ($stats, $register, $containerId, &$documentId) /** * Save current connections to the Database every 5 seconds. */ - Timer::tick(100, function () use ($stats, $getConsoleDb, $containerId, &$documentId) { + Timer::tick(5000, function () use ($stats, $getConsoleDb, $containerId, &$documentId) { foreach ($stats as $projectId => $value) { if (empty($value['connections']) && empty($value['messages'])) { continue; @@ -169,7 +169,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, $attempts = 0; $start = time(); - Timer::tick(100, function () use ($server, $register, $realtime, $stats) { + Timer::tick(5000, function () use ($server, $register, $realtime, $stats) { /** * Sending current connections to project channels on the console project every 5 seconds. */ From 824a23e8ccf094cf5ba43169034bebefa98e57e0 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Wed, 15 Sep 2021 16:06:49 +0200 Subject: [PATCH 3/3] feat(release): prepare 0.10.4 --- CHANGES.md | 5 +++++ README.md | 6 +++--- app/init.php | 2 +- src/Appwrite/Migration/Migration.php | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 1317a3480..e95a225b8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +# Version 0.10.4 + +## Bugs +- Fixed another memory leak in realtime service (#1627) + # Version 0.10.3 ## Bugs diff --git a/README.md b/README.md index 9fb228412..2509a6ee2 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ docker run -it --rm \ --volume /var/run/docker.sock:/var/run/docker.sock \ --volume "$(pwd)"/appwrite:/usr/src/code/appwrite:rw \ --entrypoint="install" \ - appwrite/appwrite:0.10.3 + appwrite/appwrite:0.10.4 ``` ### Windows @@ -69,7 +69,7 @@ docker run -it --rm ^ --volume //var/run/docker.sock:/var/run/docker.sock ^ --volume "%cd%"/appwrite:/usr/src/code/appwrite:rw ^ --entrypoint="install" ^ - appwrite/appwrite:0.10.3 + appwrite/appwrite:0.10.4 ``` #### PowerShell @@ -79,7 +79,7 @@ docker run -it --rm , --volume /var/run/docker.sock:/var/run/docker.sock , --volume ${pwd}/appwrite:/usr/src/code/appwrite:rw , --entrypoint="install" , - appwrite/appwrite:0.10.3 + appwrite/appwrite:0.10.4 ``` Once the Docker installation completes, go to http://localhost to access the Appwrite console from your browser. Please note that on non-linux native hosts, the server might take a few minutes to start after installation completes. diff --git a/app/init.php b/app/init.php index 1e38e734a..8c1d6cb45 100644 --- a/app/init.php +++ b/app/init.php @@ -49,7 +49,7 @@ const APP_MODE_DEFAULT = 'default'; const APP_MODE_ADMIN = 'admin'; const APP_PAGING_LIMIT = 12; const APP_CACHE_BUSTER = 160; -const APP_VERSION_STABLE = '0.10.3'; +const APP_VERSION_STABLE = '0.10.4'; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_FUNCTIONS = '/storage/functions'; const APP_STORAGE_CACHE = '/storage/cache'; diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index b7aac0392..2ab1ce4fd 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -47,6 +47,7 @@ abstract class Migration '0.10.1' => 'V09', '0.10.2' => 'V09', '0.10.3' => 'V09', + '0.10.4' => 'V09', ]; /**