Skip to content

Commit

Permalink
[FIX] server.py: cron trigger in recovery
Browse files Browse the repository at this point in the history
When setting up the PG replication, the slave is considered in recovery
mode. However, `LISTEN / NOTIFY` is not supported in this mode, leading
to an endless loop of crashes.

In recovery mode, we simply deactivate the feature.

closes odoo#87619

X-original-commit: 6389a64
Signed-off-by: Nicolas Martinelli (nim) <[email protected]>
  • Loading branch information
nim-odoo committed Mar 31, 2022
1 parent d9ee3a0 commit 3bdba8b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions odoo/service/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,13 @@ def cron_thread(self, number):
conn = odoo.sql_db.db_connect('postgres')
with conn.cursor() as cr:
pg_conn = cr._cnx
cr.execute("LISTEN cron_trigger")
# LISTEN / NOTIFY doesn't work in recovery mode
cr.execute("SELECT pg_is_in_recovery()")
in_recovery = cr.fetchone()[0]
if not in_recovery:
cr.execute("LISTEN cron_trigger")
else:
_logger.warning("PG cluster in recovery mode, cron trigger not activated")
cr.commit()

while True:
Expand Down Expand Up @@ -1162,7 +1168,13 @@ def start(self):

dbconn = odoo.sql_db.db_connect('postgres')
self.dbcursor = dbconn.cursor()
self.dbcursor.execute("LISTEN cron_trigger")
# LISTEN / NOTIFY doesn't work in recovery mode
self.dbcursor.execute("SELECT pg_is_in_recovery()")
in_recovery = self.dbcursor.fetchone()[0]
if not in_recovery:
self.dbcursor.execute("LISTEN cron_trigger")
else:
_logger.warning("PG cluster in recovery mode, cron trigger not activated")
self.dbcursor.commit()

def stop(self):
Expand Down

0 comments on commit 3bdba8b

Please sign in to comment.