From 5c72655e186982bb28aa4190bb57e82049a88d82 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Tue, 25 Jun 2019 12:58:11 +0200 Subject: [PATCH] [FIX] runbot: invalidate cache at each commit. In some rare case db could become inconsistent if some data in cache were used between two _schedule loop turn. --- runbot/models/build.py | 4 ++++ runbot/models/build_config.py | 1 + runbot/models/repo.py | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/runbot/models/build.py b/runbot/models/build.py index 7b1565f3..43289dfe 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -508,6 +508,7 @@ class runbot_build(models.Model): for build in self: self.env.cr.commit() # commit between each build to minimise transactionnal errors due to state computations + self.invalidate_cache() if build.local_state == 'deathrow': build._kill(result='manually_killed') continue @@ -607,6 +608,8 @@ class runbot_build(models.Model): # cleanup only needed if it was not killed if build.local_state == 'done': build._local_cleanup() + self.env.cr.commit() + self.invalidate_cache() def _path(self, *l, **kw): """Return the repo build path""" @@ -794,6 +797,7 @@ class runbot_build(models.Model): self.env.cr.commit() build._github_status() build._local_cleanup() + self.invalidate_cache() def _ask_kill(self): # todo xdo, should we kill or skip children builds? it looks like yes, but we need to be carefull if subbuild can be duplicates diff --git a/runbot/models/build_config.py b/runbot/models/build_config.py index e6571857..d8369630 100644 --- a/runbot/models/build_config.py +++ b/runbot/models/build_config.py @@ -261,6 +261,7 @@ class ConfigStep(models.Model): build_path = build._path() build_port = build.port self.env.cr.commit() # commit before docker run to be 100% sure that db state is consistent with dockers + self.invalidate_cache() return docker_run(build_odoo_cmd(cmd), log_path, build_path, docker_name, exposed_ports=[build_port, build_port + 1]) def _run_odoo_install(self, build, log_path): diff --git a/runbot/models/repo.py b/runbot/models/repo.py index 45f6d838..9c7abcb6 100644 --- a/runbot/models/repo.py +++ b/runbot/models/repo.py @@ -370,6 +370,7 @@ class runbot_repo(models.Model): build_ids = Build.search(domain_host + [('local_state', 'in', ['testing', 'running', 'deathrow'])]) build_ids._schedule() self.env.cr.commit() + self.invalidate_cache() # launch new tests @@ -382,6 +383,7 @@ class runbot_repo(models.Model): # commit transaction to reduce the critical section duration def allocate_builds(where_clause, limit): self.env.cr.commit() + self.invalidate_cache() # self-assign to be sure that another runbot instance cannot self assign the same builds query = """UPDATE runbot_build @@ -421,7 +423,6 @@ class runbot_repo(models.Model): pending_build = Build.search(domain_host + [('local_state', '=', 'pending')], limit=available_slots) if pending_build: pending_build._schedule() - self.env.cr.commit() # terminate and reap doomed build build_ids = Build.search(domain_host + [('local_state', '=', 'running')]).ids