Actually there probably is an error. I would not expect you to see this message ever, unless something is really "stuck". The lock is only used when calculating which scheduled task to run next. This should happen really quickly. What could be happening, is that your cron jobs are crashing, or being terminated - and are not automatically cleaning up their locks.
Moodle supports different lock factories - and the best one depends on your
database/OS etc.
Here are the docs about lock factories from config-dist.php:
// Moodle 2.7 introduces a locking api for critical tasks (e.g. cron).
// The default locking system to use is DB locking for
Postgres, and file locking for
//
MySQL,
Oracle and
SQLServer. If $CFG->preventfilelocking is set, then the default
// will always be DB locking. It can be manually set to one of the lock
// factory classes listed below, or one of your own custom classes implementing the
// \core\lock\lock_factory interface.
//
// $CFG->lock_factory = "auto";
//
// The list of available lock factories is:
//
// "\\core\\lock\\file_lock_factory" - File locking
// Uses lock files stored by default in the
dataroot. Whether this
// works on clusters depends on the file system used for the dataroot.
//
// "\\core\\lock\\db_record_lock_factory" - DB locking based on table rows.
//
// "\\core\\lock\\postgres_lock_factory" - DB locking based on postgres advisory locks.
//
// Settings used by the lock factories
//
// Location for lock files used by the File locking factory. This must exist
// on a shared file system that supports locking.
// $CFG->lock_file_root = $CFG->dataroot . '/lock';
I would recommend you change to a different supported lock_factory if you are having trouble with your current one.