Open alexeyklyukin opened 7 years ago
Hey Oleksii, thanks for the report.
The first issue seems most pressing and is now resolved on master.
For the second issue, your fix looks ok (with SetLatch), but it only addresses the case in which there are no jobs. Usually, pg_cron waits in poll
. The problem is that we cannot easily wait for both sockets and a latch. PostgreSQL does have a convenient WaitLatckOrSocket
function, but it only takes one socket, while pg_cron needs to wait for multiple sockets.
In PostgreSQL 9.6 this issue can be resolved using wait event sets, which allow you to wait for a latch and multiple sockets. To support PostgreSQL 9.5, I'm considering using a self-pipe, which also takes away the need to do pg_usleep
/WaitLatch
when there are no tasks.
When postmaster reinitializes postgres processes because of the crash of one of them, pg_cron is terminated and is not subsequently restarted. The reason is that it supplies the BGW_NEVER_RESTART flag to the RegisterBackgroundWorker. I wonder why?
The other issue is that pg_cron continues to run when postmaster dies (i.e. killed by -9). The docs actually deal with that:
That's quite easy to fix:
I think there should be a few additional changes, namely WaitLatch should go to the main loop and the signals should SetLatch as well. What do you think?