pg_cron
pg_cron copied to clipboard
pg_cron hangs when cron.max_running_jobs is exceeded
There is a bug in the state machine that causes pg_cron to indefinitely wait for jobs that it thinks are running, but are actually idle.
I can't tell exactly where the bug is, but it happens when max_running_jobs
is exceeded.
Here is a way to reproduce it:
-
Set
cron.max_running_jobs = 1
inpostgresql.conf
and start PostgreSQL. -
Define two jobs:
SELECT cron.schedule('* * * * *', 'SELECT pg_sleep(30)'); SELECT cron.schedule('* * * * *', 'SELECT pg_sleep(30)');
First one of the jobs is started. When that one is done, the other one is started. The second job never finishes, although the connection has become idle.
We end up with max_running_jobs
idle connections that completely block pg_cron
.
Attaching to the pg_cron
with gdb shows an endless repetition of
poll([{fd=-1}], 1, 1000) = 0 (Timeout)
I have opened a pull request for a patch that fixed the issue for me.
Not sure if that patch is correct though.