Skip to content

Commit 78513bb

Browse files
lbussellCopilot
andauthored
Add retry logic to issue comment and close in NotificationService (#2026)
The GitHub API has eventual consistency - a newly created issue may not be fully propagated across GitHub's backend services when the first comment or close request arrives. This was observed as an ApiValidationException ("could not resolve to a node") on the comment step in build#2925294. Wrap both the comment creation and issue close calls with the existing RetryHelper policy (5 retries, jittered exponential backoff) to handle these transient failures. Related: dotnet/dotnet-docker-internal#10232 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent db91e0d commit 78513bb

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/ImageBuilder/NotificationService.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public async Task PostAsync(
4949
{
5050
foreach (string comment in comments)
5151
{
52-
IssueComment postedComment =
53-
await github.Issue.Comment.Create(repoOwner, repoName, issue.Number, comment);
52+
await RetryHelper.GetWaitAndRetryPolicy<ApiException>(_logger)
53+
.ExecuteAsync(() =>
54+
github.Issue.Comment.Create(repoOwner, repoName, issue.Number, comment));
5455
}
5556
}
5657
}
@@ -80,11 +81,15 @@ public async Task PostAsync(
8081
return;
8182
}
8283

83-
// Immediately close issues which aren't failures, since open issues should represent actionable items
84+
// Immediately close issues which aren't failures, since open issues should represent actionable items.
85+
// Retry with backoff to handle GitHub's eventual consistency - the issue may not be fully
86+
// propagated across GitHub's backend services immediately after creation.
8487
if (!labels.Where(l => l.Contains(Commands.NotificationLabels.Failure)).Any())
8588
{
8689
_logger.LogInformation("No failure label found in the notification labels.");
87-
await github.Issue.Update(repoOwner, repoName, issue.Number, new IssueUpdate { State = ItemState.Closed });
90+
await RetryHelper.GetWaitAndRetryPolicy<ApiException>(_logger)
91+
.ExecuteAsync(() =>
92+
github.Issue.Update(repoOwner, repoName, issue.Number, new IssueUpdate { State = ItemState.Closed }));
8893
}
8994
}
9095
}

0 commit comments

Comments
 (0)