From 63f7805aa2bf72987061f2528cfc30479fc94398 Mon Sep 17 00:00:00 2001 From: "Georg A. G. Notter" Date: Fri, 11 Sep 2020 11:19:47 +0200 Subject: [PATCH 1/2] [IMP] - keep connexion alive in case of job inactivity --- queue_job/jobrunner/runner.py | 11 +++++++++++ queue_job/readme/CONTRIBUTORS.rst | 1 + 2 files changed, 12 insertions(+) diff --git a/queue_job/jobrunner/runner.py b/queue_job/jobrunner/runner.py index 0a633b45e9..416fbbac91 100644 --- a/queue_job/jobrunner/runner.py +++ b/queue_job/jobrunner/runner.py @@ -330,6 +330,11 @@ def select_jobs(self, where, args): cr.execute(query, args) return list(cr.fetchall()) + def keep_alive(self): + query = "SELECT 1" + with closing(self.conn.cursor()) as cr: + cr.execute(query) + def set_job_enqueued(self, uuid): with closing(self.conn.cursor()) as cr: cr.execute("UPDATE queue_job SET state=%s, " @@ -408,6 +413,12 @@ def run_jobs(self): def process_notifications(self): for db in self.db_by_name.values(): + if not db.conn.notifies: + # If there are no activity in the queue_job table it seems that + # tcp keepalives are not sent (in that very specific scenario), + # causing some intermediaries (such as haproxy) to close the + # connection, making the jobrunner to restart on a socket error + db.keep_alive() while db.conn.notifies: if self._stop: break diff --git a/queue_job/readme/CONTRIBUTORS.rst b/queue_job/readme/CONTRIBUTORS.rst index 63d1d390a4..58cb5a9d08 100644 --- a/queue_job/readme/CONTRIBUTORS.rst +++ b/queue_job/readme/CONTRIBUTORS.rst @@ -6,3 +6,4 @@ * Laurent Mignon * Laetitia Gangloff * Cédric Pigeon +* Georg A. G. Notter From 771e577aaaa55814b855dbe354f89c192d7a6dfd Mon Sep 17 00:00:00 2001 From: "Georg A. G. Notter" Date: Thu, 25 Mar 2021 14:40:59 +0100 Subject: [PATCH 2/2] Update CONTRIBUTORS.rst --- queue_job/readme/CONTRIBUTORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/queue_job/readme/CONTRIBUTORS.rst b/queue_job/readme/CONTRIBUTORS.rst index 58cb5a9d08..e049f26f52 100644 --- a/queue_job/readme/CONTRIBUTORS.rst +++ b/queue_job/readme/CONTRIBUTORS.rst @@ -6,4 +6,5 @@ * Laurent Mignon * Laetitia Gangloff * Cédric Pigeon +* Souheil Bejaoui * Georg A. G. Notter