You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Occasionally this error is being logged when running cron loop on multiple containers with PostgreSQL database.
Traceback (most recent call last):
File "/opt/app-root/lib64/python3.9/site-packages/django_cron/management/commands/runcrons.py", line 82, in run_cron_with_cache_check
manager.run(force)
File "/opt/app-root/lib64/python3.9/site-packages/django_cron/__init__.py", line 292, in run
self.stdout.write(u"[ ] {0}\n".format(self.cron_job.code))
File "/opt/app-root/lib64/python3.9/site-packages/django_cron/backends/lock/base.py", line 66, in __exit__
self.release()
File "/usr/lib64/python3.9/contextlib.py", line 79, in inner
return func(*args, **kwds)
File "/opt/app-root/lib64/python3.9/site-packages/django_cron/backends/lock/database.py", line 25, in release
lock.locked = False
AttributeError: 'NoneType' object has no attribute 'locked'
The text was updated successfully, but these errors were encountered:
I believe this problem is caused because the lock method of database.py allows two or more threads to set the locked attribute to true. If both threads select the record before it is locked, then both threads will believe that it has obtained an exclusive lock on the cron job. This could be corrected by adding a select_for_update to the get_or_create. Like follows:
lock, created = CronJobLock.objects.select_for_update().get_or_create(job_name=self.job_name)
That will force the second thread to wait until update has been saved.
Occasionally this error is being logged when running cron loop on multiple containers with PostgreSQL database.
The text was updated successfully, but these errors were encountered: