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

possible to set memcache 'expire' on locks? #12

Closed
reedgz opened this issue Jun 11, 2015 · 4 comments
Closed

possible to set memcache 'expire' on locks? #12

reedgz opened this issue Jun 11, 2015 · 4 comments

Comments

@reedgz
Copy link

reedgz commented Jun 11, 2015

Hi, First of all thanks for the great library! Here I have some problems with un-released locks.

I am calling many 3rd party libraries between lock & release. Very occasionally I could get a fatal crash that the lock is never cleaned up.

My process typically takes 3~5 sec to complete, is it possible to set an expire value for the lock?
E.g. 60 sec, so it is not locked forever.

I could see the alternative maybe using flock so file system handles it...

My code is very simple like this:

$mutex = new Mutex('very-critical-stuff', $lock);
if ($mutex->acquireLock(1000)) {
    // calling many 3rd party libraries.
    // !!! Fatal error crash.
    // the lock is never released
    $mutex->releaseLock();
} else {
    throw new Exception('Unable to gain lock!');
}
@arvenil
Copy link
Owner

arvenil commented Jun 13, 2015

#13 Will that work for you?

@reedgz
Copy link
Author

reedgz commented Jun 13, 2015

@arvenil You are awesome!
I carefully read everything you wrote in the fix. It will work for me but I wouldn't recommend it for anyone else. I should use an expire time like 100x of the typical processing time.

It is up to you to merge this into master branch. The potential racing problem is pretty hard to deal with. I don't want people complain about ninjia-mutex because of this change; changing my code to use flock or mySQL is probably easier.

@arvenil
Copy link
Owner

arvenil commented Jun 13, 2015

Awesome :)

No worries, the ->setExpiration() method is optional, by default there is no expiration. Just a warning that it may be dangerous should be enough.

Thanks for your issue report! :)

arvenil added a commit that referenced this issue Jun 13, 2015
#12: Add expiration time for memcache lock storage
@arvenil
Copy link
Owner

arvenil commented Jun 16, 2015

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

No branches or pull requests

2 participants