Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release mutex if process is killed #80

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
Open

Conversation

danog
Copy link
Sponsor Contributor

@danog danog commented Dec 9, 2023

Fixes #79

@@ -20,39 +19,16 @@ public function __construct(private readonly string $fileName)

public function acquire(): Lock
{
// Try to create the lock file. If the file already exists, someone else
// has the lock, so set an asynchronous timer and try again.
$f = \fopen($this->fileName, 'c');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not touch here?

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a one-time cost, not really worth adding a touch here imo

$lock = new Lock($this->release(...));

$file->close();
$lock = new Lock(fn () => \flock($f, LOCK_UN));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will block for a short duration, no?

Copy link
Sponsor Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered adding a variant that used parallel but decided that the overhead to communicate to/from the IPC worker will be way worse than that of a single syscall that returns immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

FileMutex does not release mutex if process is killed
2 participants