Manually release a lock?

Manually release a lock?

by Michael Aherne -
Number of replies: 5
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Does anyone know if the locking framework in Moodle has a way to release a lock? We're having trouble with a scheduled task which crashed halfway through and now won't run ("Cannot obtain task lock"). 

I tried purging caches but that didn't affect it. I can see there's a release_lock() function in the locking framework, but can't figure out if there's a way to get that to run without writing a custom script.

This is on Moodle 2.8.3+ on RHEL with MySQL (so I think it's using the file locking implementation)

Average of ratings: -
In reply to Michael Aherne

Re: Manually release a lock?

by Damyon Wiese -
Yes it should be using the file locking implementation, but that means it should release the lock if the process ended (even if it crashed).

Check for still running php processes, maybe it's just still processing?
Average of ratings: Useful (1)
In reply to Damyon Wiese

Re: Manually release a lock?

by Michael Aherne -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Sorry, when I say it crashed, I mean that we had server problems and the process was killed somehow, rather than that the task code itself failed, so it doesn't seem to have had a chance to run any of the clean up code. I'll maybe try rebooting it, but if that doesn't fix it, would finding and deleting the lock file work?

In reply to Michael Aherne

Re: Manually release a lock?

by Damyon Wiese -
Restarting apache should do it. Not sure about deleting a file (because a file is not really deleted until all open file handles are closed).

Is your data root using an unusual file system ?
Average of ratings: Useful (1)
In reply to Damyon Wiese

Re: Manually release a lock?

by Damyon Wiese -
If you are having problems with file locks, you can switch to DB locks like this:

$CFG->lock_factory = '\\core\\lock\\db_record_lock_factory';
Average of ratings: Useful (1)
In reply to Damyon Wiese

Re: Manually release a lock?

by Michael Aherne -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Thanks, Damyon. I ended up locating and deleting the file and it worked fine after that. The filesystem is just a standard ext4  one.

Does the database locking work OK on MySQL? I was assuming that the fact that Moodle uses DB locking by default for Postgres but not for MySQL meant there was some kind of suboptimal behaviour?