From 8887a92d4be8b0e8ed1b6f944a7ee21090442af6 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 16 May 2017 21:20:22 +0100 Subject: [PATCH 1/3] Removed useless break statements --- src/pocketmine/PocketMine.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 5699e1722..29317e941 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -227,7 +227,6 @@ namespace pocketmine { } return parse_offset($offset); - break; case 'linux': // Ubuntu / Debian. if(file_exists('/etc/timezone')){ @@ -254,7 +253,6 @@ namespace pocketmine { } return parse_offset($offset); - break; case 'mac': if(is_link('/etc/localtime')){ $filename = readlink('/etc/localtime'); @@ -265,10 +263,8 @@ namespace pocketmine { } return false; - break; default: return false; - break; } } From 00e6d6a6b14385d84837021e46d142c93a02730d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 17 May 2017 15:43:44 +0100 Subject: [PATCH 2/3] Fixed AsyncTask memory leak (#922) * Added PocketMine-TesterPlugin submodule with regression test --- .gitmodules | 3 +++ src/pocketmine/scheduler/AsyncPool.php | 4 ++++ src/pocketmine/scheduler/AsyncTask.php | 3 ++- tests/plugins/PocketMine-TesterPlugin | 1 + tests/travis.sh | 18 +++++++++++++++++- 5 files changed, 27 insertions(+), 2 deletions(-) create mode 160000 tests/plugins/PocketMine-TesterPlugin diff --git a/.gitmodules b/.gitmodules index 30ef58db1..df60ddab7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,6 @@ [submodule "tests/plugins/PocketMine-DevTools"] path = tests/plugins/PocketMine-DevTools url = https://github.com/pmmp/PocketMine-DevTools.git +[submodule "tests/plugins/PocketMine-TesterPlugin"] + path = tests/plugins/PocketMine-TesterPlugin + url = https://github.com/pmmp/PocketMine-TesterPlugin.git diff --git a/src/pocketmine/scheduler/AsyncPool.php b/src/pocketmine/scheduler/AsyncPool.php index 22433690c..f9480bf2d 100644 --- a/src/pocketmine/scheduler/AsyncPool.php +++ b/src/pocketmine/scheduler/AsyncPool.php @@ -158,6 +158,10 @@ class AsyncPool{ } } + foreach($this->workers as $worker){ + $worker->collect(); + } + Timings::$schedulerAsyncTimer->stopTiming(); } } diff --git a/src/pocketmine/scheduler/AsyncTask.php b/src/pocketmine/scheduler/AsyncTask.php index 68491511c..cd50ac11e 100644 --- a/src/pocketmine/scheduler/AsyncTask.php +++ b/src/pocketmine/scheduler/AsyncTask.php @@ -261,7 +261,8 @@ abstract class AsyncTask extends Collectable{ $this->{$p} = null; } } - } + $this->setGarbage(); + } } diff --git a/tests/plugins/PocketMine-TesterPlugin b/tests/plugins/PocketMine-TesterPlugin new file mode 160000 index 000000000..a282b45c1 --- /dev/null +++ b/tests/plugins/PocketMine-TesterPlugin @@ -0,0 +1 @@ +Subproject commit a282b45c1d9d2108d602ccb5df7fdef4ef364232 diff --git a/tests/travis.sh b/tests/travis.sh index 4f53ec0a6..d57da86a1 100755 --- a/tests/travis.sh +++ b/tests/travis.sh @@ -17,7 +17,11 @@ if [ $? -ne 0 ]; then exit 1 fi -cp -r tests/plugins plugins +rm server.log 2> /dev/null +mkdir -p ./plugins + +cp -r tests/plugins/PocketMine-DevTools ./plugins + "$PHP_BINARY" ./plugins/PocketMine-DevTools/src/DevTools/ConsoleScript.php --make ./plugins/PocketMine-DevTools --relative ./plugins/PocketMine-DevTools --out ./plugins/DevTools.phar rm -rf ./plugins/PocketMine-DevTools @@ -28,3 +32,15 @@ else echo No phar created! exit 1 fi + +cp -r tests/plugins/PocketMine-TesterPlugin ./plugins +"$PHP_BINARY" src/pocketmine/PocketMine.php --no-wizard --disable-ansi --disable-readline --debug.level=2 + +result=$(grep 'TesterPlugin' server.log | grep 'Finished' | grep -v 'PASS') +if [ "$result" != "" ]; then + echo "$result" + echo Some tests did not complete successfully, changing build status to failed + exit 1 +else + echo All tests passed +fi From 568e2760f1c0beba5b347c416fad231ea3025919 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Wed, 17 May 2017 19:30:50 +0100 Subject: [PATCH 3/3] Collect workers when cancelling all tasks --- src/pocketmine/scheduler/AsyncPool.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/scheduler/AsyncPool.php b/src/pocketmine/scheduler/AsyncPool.php index f9480bf2d..638169e00 100644 --- a/src/pocketmine/scheduler/AsyncPool.php +++ b/src/pocketmine/scheduler/AsyncPool.php @@ -136,6 +136,14 @@ class AsyncPool{ $this->taskWorkers = []; $this->tasks = []; + + $this->collectWorkers(); + } + + private function collectWorkers(){ + foreach($this->workers as $worker){ + $worker->collect(); + } } public function collectTasks(){ @@ -158,9 +166,7 @@ class AsyncPool{ } } - foreach($this->workers as $worker){ - $worker->collect(); - } + $this->collectWorkers(); Timings::$schedulerAsyncTimer->stopTiming(); }