file icon indicating copy to clipboard operation
file copied to clipboard

FileMutex does not release mutex if process is killed

Open danog opened this issue 1 year ago • 0 comments

<?php

use Amp\File\FileMutex;

require 'vendor/autoload.php';

$pid = pcntl_fork();

if ($pid) {
    sleep(1);
    posix_kill($pid, 9);
    var_dump("killed");

    var_dump("Trying to re-acquire lock");
    $lock = new FileMutex('/tmp/test');
    $lock->acquire();
    
    var_dump("unreachable");
} else {
    $lock = new FileMutex('/tmp/test');
    $lock->acquire();
    var_dump("Acquired lock!");
}

using flock instead of just file creation like in https://github.com/danog/MadelineProto/blob/v8/src/AsyncTools.php#L83 should fix the issue.

danog avatar Dec 08 '23 10:12 danog