PR#4413: Fix race handling in get_next_build

Merges #4413
https://pagure.io/koji/pull-request/4413

Fixes: #4414
https://pagure.io/koji/issue/4414
Fix race handling in get_next_build
This commit is contained in:
Mike McLean 2025-07-10 11:49:54 -04:00
commit adbe584a4c
2 changed files with 6 additions and 2 deletions

View file

@ -4859,9 +4859,12 @@ def get_next_build(build_info):
return new_build(build_info)
build_info['release'] = get_next_release(build_info)
for try_no in range(2, 10):
savepoint = Savepoint('get_next_build_pre_insert')
try:
return new_build(build_info)
except IntegrityError:
# using strict so we don't try to recycle
return new_build(build_info, strict=True)
except (IntegrityError, koji.GenericError):
savepoint.rollback()
build_info['release'] = get_next_release(build_info, try_no)
# otherwise
raise koji.GenericError("Can't find available release")

View file

@ -12,6 +12,7 @@ class TestGetNextBuild(unittest.TestCase):
self.get_next_release = mock.patch('kojihub.kojihub.get_next_release').start()
self.new_build = mock.patch('kojihub.kojihub.new_build').start()
self._dml = mock.patch('kojihub.kojihub._dml').start()
self.Savepoint = mock.patch('kojihub.kojihub.Savepoint').start()
self.binfo = {'name': 'name', 'version': 'version'}
def tearDown(self):