-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Exit ephemeral runners on broker acknowledge job-not-found #4540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rentziass
wants to merge
5
commits into
main
Choose a base branch
from
rentziass-fix-ephemeral-runner-ack-404-exit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+314
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4fc7538
Classify broker acknowledge job-not-found
rentziass b287711
Exit single-use runners on acknowledge job-not-found
rentziass 5d65d6f
Handle acknowledge job-not-found for hosted single-use runners
rentziass bcfe9f3
Remove unused BrokerHttpClientL0 using
rentziass 6cc27b6
Simplify ephemeral acknowledge job-not-found handling
rentziass File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,11 +256,24 @@ public async Task AcknowledgeRunnerRequestAsync( | |
| default: | ||
| break; | ||
| } | ||
|
|
||
| if (IsAcknowledgeJobNotFound(result.StatusCode, brokerError)) | ||
| { | ||
| throw new RunnerRequestJobNotFoundException(brokerError.Message); | ||
| } | ||
| } | ||
|
|
||
| throw new Exception($"Failed to acknowledge runner request. Request to {requestUri} failed with status: {result.StatusCode}. Error message {result.Error}"); | ||
| } | ||
|
|
||
| private static bool IsAcknowledgeJobNotFound(HttpStatusCode statusCode, BrokerError brokerError) | ||
| { | ||
| return statusCode == HttpStatusCode.NotFound && | ||
| brokerError?.StatusCode == (int)HttpStatusCode.NotFound && | ||
| !string.Equals(brokerError.ErrorKind, BrokerErrorKind.RunnerNotFound, StringComparison.Ordinal) && | ||
| string.Equals(brokerError.Message, "Job not found", StringComparison.OrdinalIgnoreCase); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you help me understand more about this? Is there an error kind we could rely on, instead of message? I'm worried relying on the error message might be fragile. That's why error kind exists. |
||
| } | ||
|
|
||
| private static bool TryParseErrorBody(string errorBody, out BrokerError error) | ||
| { | ||
| if (!string.IsNullOrEmpty(errorBody)) | ||
|
|
||
23 changes: 23 additions & 0 deletions
23
src/Sdk/WebApi/WebApi/Exceptions/RunnerRequestJobNotFoundException.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using System; | ||
|
|
||
| namespace GitHub.Services.WebApi | ||
| { | ||
| [Serializable] | ||
| public sealed class RunnerRequestJobNotFoundException : Exception | ||
| { | ||
| public RunnerRequestJobNotFoundException() | ||
| : base() | ||
| { | ||
| } | ||
|
|
||
| public RunnerRequestJobNotFoundException(String message) | ||
| : base(message) | ||
| { | ||
| } | ||
|
|
||
| public RunnerRequestJobNotFoundException(String message, Exception innerException) | ||
| : base(message, innerException) | ||
| { | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| using System; | ||
| using System.Net; | ||
| using System.Net.Http; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using GitHub.DistributedTask.WebApi; | ||
| using GitHub.Runner.Sdk; | ||
| using GitHub.Services.WebApi; | ||
| using Xunit; | ||
|
Copilot marked this conversation as resolved.
|
||
|
|
||
| namespace GitHub.Actions.RunService.WebApi.Tests; | ||
|
|
||
| public sealed class BrokerHttpClientL0 | ||
| { | ||
| [Fact] | ||
| public async Task AcknowledgeRunnerRequestAsyncThrowsRunnerRequestJobNotFoundException() | ||
| { | ||
| using var client = CreateClient( | ||
| HttpStatusCode.NotFound, | ||
| new BrokerError | ||
| { | ||
| Source = "actions-broker-listener", | ||
| StatusCode = (int)HttpStatusCode.NotFound, | ||
| Message = "Job not found", | ||
| }); | ||
|
|
||
| await Assert.ThrowsAsync<RunnerRequestJobNotFoundException>(() => | ||
| client.AcknowledgeRunnerRequestAsync("runner-request", Guid.NewGuid(), "2.0.0", TaskAgentStatus.Online, cancellationToken: CancellationToken.None)); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task AcknowledgeRunnerRequestAsyncKeepsRunnerNotFoundClassification() | ||
| { | ||
| using var client = CreateClient( | ||
| HttpStatusCode.NotFound, | ||
| new BrokerError | ||
| { | ||
| Source = "actions-broker-listener", | ||
| ErrorKind = BrokerErrorKind.RunnerNotFound, | ||
| StatusCode = (int)HttpStatusCode.NotFound, | ||
| Message = "Runner not found", | ||
| }); | ||
|
|
||
| await Assert.ThrowsAsync<RunnerNotFoundException>(() => | ||
| client.AcknowledgeRunnerRequestAsync("runner-request", Guid.NewGuid(), "2.0.0", TaskAgentStatus.Online, cancellationToken: CancellationToken.None)); | ||
| } | ||
|
|
||
| private static BrokerHttpClient CreateClient(HttpStatusCode statusCode, BrokerError brokerError) | ||
| { | ||
| return new BrokerHttpClient( | ||
| new Uri("https://broker.actions.githubusercontent.com/"), | ||
| new StaticResponseHandler(new HttpResponseMessage(statusCode) | ||
| { | ||
| Content = new StringContent(JsonUtility.ToString(brokerError), Encoding.UTF8, "application/json"), | ||
| }), | ||
| disposeHandler: true); | ||
| } | ||
|
|
||
| private sealed class StaticResponseHandler : HttpMessageHandler | ||
| { | ||
| private readonly HttpResponseMessage _response; | ||
|
|
||
| public StaticResponseHandler(HttpResponseMessage response) | ||
| { | ||
| _response = response; | ||
| } | ||
|
|
||
| protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
| { | ||
| _response.RequestMessage = request; | ||
| return Task.FromResult(_response); | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this merge with the switch above somehow? since they are both kind of checking the brokererror and throw exception.