Skip to content

Commit 793ec2a

Browse files
authored
fix(command): add coordinator cleanup in command execution finally block (#7545)
* fix(command): add coordinator cleanup in command execution finally block - Add CoordinatorManager::until(Constants::WORKER_EXIT)->resume() in finally block - Ensure proper cleanup of coordinators after command execution - Wrap in try-catch to prevent exceptions from interrupting cleanup flow * fix(composer): update hyperf/coordinator version requirement * fix(command): conditionally resume coordinator on auto exit * fix(listener): comment out deprecated resume logic in ResumeExitCoordinatorListener * fix(changelog): add entry for coordinator resume in command execution finally block --------- Co-authored-by: Deeka Wong <8337659+huangdijia@users.noreply.github.com>
1 parent 79188b4 commit 793ec2a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"hyperf/collection": "~3.1.0",
1414
"hyperf/context": "~3.1.0",
1515
"hyperf/contract": "~3.1.0",
16+
"hyperf/coordinator": "~3.1.0",
1617
"hyperf/coroutine": "~3.1.0",
1718
"hyperf/di": "~3.1.0",
1819
"hyperf/stringable": "~3.1.0",

src/Command.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace Hyperf\Command;
1414

15+
use Hyperf\Coordinator\Constants;
16+
use Hyperf\Coordinator\CoordinatorManager;
1517
use Hyperf\Coroutine\Coroutine;
1618
use Psr\EventDispatcher\EventDispatcherInterface;
1719
use Swoole\ExitException;
@@ -195,6 +197,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
195197
$this->eventDispatcher->dispatch(new Event\FailToHandle($this, $exception));
196198
} finally {
197199
$this->eventDispatcher?->dispatch(new Event\AfterExecute($this, $exception ?? null));
200+
201+
try {
202+
if ($this->getApplication()->isAutoExitEnabled()) {
203+
CoordinatorManager::until(Constants::WORKER_EXIT)->resume();
204+
}
205+
} catch (Throwable) {
206+
}
198207
}
199208

200209
return $this->exitCode;

0 commit comments

Comments
 (0)