Skip to content

Commit ce600b9

Browse files
Merge pull request #195 from Mark-Simulacrum/retry-push
* 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.
2 parents c6926e6 + 30da512 commit ce600b9

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

homu/main.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ def synchronize(repo_label, repo_cfg, logger, gh, states, repos, db, mergeable_q
16681668

16691669
def process_config(config):
16701670
# Replace environment variables
1671-
if type(config) == str:
1671+
if type(config) is str:
16721672
for var in VARIABLES_RE.findall(config):
16731673
try:
16741674
config = config.replace("${"+var+"}", os.environ[var])
@@ -1680,9 +1680,9 @@ def process_config(config):
16801680

16811681
return config
16821682
# Recursively apply the processing
1683-
elif type(config) == list:
1683+
elif type(config) is list:
16841684
return [process_config(item) for item in config]
1685-
elif type(config) == dict:
1685+
elif type(config) is dict:
16861686
return {key: process_config(value) for key, value in config.items()}
16871687
# All other values should be returned as-is
16881688
else:

homu/server.py

+28-7
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)