Skip to content

Commit 4fd59be

Browse files
Retry set_ref up to 5 times
This hopefully reduces the rate of these exceptions we see on PRs, but since we don't know the exact cause we'll have to see if it actually works.
1 parent c6926e6 commit 4fd59be

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

homu/server.py

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from retrying import retry
3838
import random
3939
import string
40+
import time
4041

4142
import bottle
4243
bottle.BaseRequest.MEMFILE_MAX = 1024 * 1024 * 10
@@ -690,6 +691,13 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
690691
)
691692

692693
if state.approved_by and not state.try_:
694+
# The set_ref call below sometimes fails with 422 failed to
695+
# fast forward. We believe this is a spurious error on GitHub's
696+
# side, though it's not entirely clear why. We sleep for 1
697+
# minute before trying it after setting the status to try to
698+
# increase the likelihood it will work, and also retry the
699+
# set_ref a few times.
700+
time.sleep(60)
693701
state.add_comment(comments.BuildCompleted(
694702
approved_by=state.approved_by,
695703
base_ref=state.base_ref,
@@ -698,31 +706,44 @@ def report_build_res(succ, url, builder, state, logger, repo_cfg):
698706
))
699707
state.change_labels(LabelEvent.SUCCEED)
700708

701-
def set_ref():
709+
def set_ref_inner():
702710
utils.github_set_ref(state.get_repo(), 'heads/' +
703711
state.base_ref, state.merge_sha)
704712
if state.test_on_fork is not None:
705713
utils.github_set_ref(state.get_test_on_fork_repo(),
706714
'heads/' + state.base_ref,
707715
state.merge_sha, force=True)
708-
try:
716+
717+
def set_ref():
709718
try:
710-
set_ref()
719+
set_ref_inner()
711720
except github3.models.GitHubError:
712721
utils.github_create_status(
713722
state.get_repo(),
714723
state.merge_sha,
715724
'success', '',
716725
'Branch protection bypassed',
717726
context='homu')
718-
set_ref()
727+
set_ref_inner()
719728

720-
state.fake_merge(repo_cfg)
729+
error = None
730+
for i in range(0, 5):
731+
try:
732+
set_ref()
733+
state.fake_merge(repo_cfg)
734+
error = None
735+
except github3.models.GitHubError as e:
736+
error = e
737+
pass
738+
if error is None:
739+
break
740+
else:
741+
time.sleep(10)
721742

722-
except github3.models.GitHubError as e:
743+
if error is not None:
723744
state.set_status('error')
724745
desc = ('Test was successful, but fast-forwarding failed:'
725-
' {}'.format(e))
746+
' {}'.format(error))
726747
utils.github_create_status(state.get_repo(),
727748
state.head_sha, 'error', url,
728749
desc, context='homu')

0 commit comments

Comments
 (0)