From 7058868c0f9c8a928439fa712b22cd4b02ffb5b5 Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Fri, 17 Jan 2020 12:18:31 +0100 Subject: [PATCH] [IMP] runbot: select for update in ask_kill When a build has a lot of children, _ask_kill can fail due to concurrent_update. This solution locks all build before reading/updating builds. --- runbot/models/build.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runbot/models/build.py b/runbot/models/build.py index a11c750a..5ca8eb5f 100644 --- a/runbot/models/build.py +++ b/runbot/models/build.py @@ -868,8 +868,9 @@ class runbot_build(models.Model): build._github_status() 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 + def _ask_kill(self, lock=True): + if lock: + self.env.cr.execute("""SELECT id FROM runbot_build WHERE parent_path like %s FOR UPDATE""", ['%s%%' % self.parent_path]) self.ensure_one() user = request.env.user if request else self.env.user uid = user.id @@ -888,7 +889,7 @@ class runbot_build(models.Model): build._log('_ask_kill', 'Killing build %s, requested by %s (user #%s)' % (build.dest, user.name, uid)) for child in build.children_ids: # should we filter build that are target of a duplicate_id? if not child.duplicate_id: - child._ask_kill() + child._ask_kill(lock=False) def _wake_up(self): build = self.real_build