Skip to content

Commit

Permalink
Fix lock release errors on each deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed Apr 18, 2024
1 parent 3d7fcd7 commit f840c61
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Command/RunWorkersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
use App\Service\QueueWorker;
use Symfony\Component\Lock\Exception\LockReleasingException;

class RunWorkersCommand extends Command
{
Expand Down Expand Up @@ -75,7 +76,19 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->logger->notice('Worker exiting successfully');
} finally {
$this->release();
try {
$this->release();
} catch (LockReleasingException $e) {
// during deployments the system v semaphore somehow gets removed before the previous
// deploy's processes are stopped so this fails to release the lock but is not an actual problem
if (!str_contains((string) $e->getPrevious()?->getMessage(), 'does not (any longer) exist')) {
throw $e;
}
try {
// force destructor as that will trigger another lock release attempt
$this->lock = null;
} catch (LockReleasingException) {}

Check failure on line 90 in src/Command/RunWorkersCommand.php

View workflow job for this annotation

GitHub Actions / PHPStan

Dead catch - Symfony\Component\Lock\Exception\LockReleasingException is never thrown in the try block.
}
}

return 0;
Expand Down

0 comments on commit f840c61

Please sign in to comment.