laravel-aws-worker icon indicating copy to clipboard operation
laravel-aws-worker copied to clipboard

lock/mutex is never cleaned up when running a command with runInBackground()

Open zandzpider opened this issue 7 years ago • 1 comments
trafficstars

<?php
$schedule
   ->command('some-command')
   ->runInBackground()
   ->withoutOverlapping()
   ->everyMinute();

running this with the console command php artisan schedule:run works perfectly and cleans up the lock file as expected.

if i remove "runInBackground" everything works as expected. with runInBackground it seems to run the code but never cleans up which causes future events to not be run

this actually stopped working after i upgraded from laravel 5.3 to 5.5.

no exceptions or other warnings are thrown

image

zandzpider avatar Apr 26 '18 10:04 zandzpider

i've drilled down on what is happening here. i'll give it a shot on explaining it. if it's unclear, just tell me and i'll explain some more.

the issue is the way the name of the lock file is generated.

when you run the command, it generates the mutex/lock string (this is in the Laravel code)

return 'framework'.DIRECTORY_SEPARATOR.'schedule-'.sha1($this->expression.$this->command);'

the issue is with the command section. it contains the PHP executable. and that executable can be different when the command is sent to the background. because the CLI will pick it up.

example of the command in browser and cli (sent to background)

          • *'/usr/bin/php7.0' 'artisan' YOUR_COMMAND:HERE
          • *'/usr/bin/php7' 'artisan' YOUR_COMMAND:HERE

because of this, the hash is different for the mutex/lock file

zandzpider avatar Apr 27 '18 11:04 zandzpider