Report infra_error for action download failures. (#4294)

This commit is contained in:
Tingluo Huang
2026-03-16 13:31:57 +00:00
committed by GitHub
parent c5dcf59d26
commit 45ed15ddf3
3 changed files with 104 additions and 67 deletions
+17
View File
@@ -115,6 +115,14 @@ namespace GitHub.Runner.Worker
executionContext.Result = TaskResult.Failed; executionContext.Result = TaskResult.Failed;
throw; throw;
} }
catch (FailedToDownloadActionException ex)
{
// Log the error and fail the PrepareActionsAsync Initialization.
Trace.Error($"Caught exception from PrepareActionsAsync Initialization: {ex}");
executionContext.InfrastructureError(ex.InnerException?.Message ?? ex.Message, category: "error_download_action");
executionContext.Result = TaskResult.Failed;
throw;
}
catch (InvalidActionArchiveException ex) catch (InvalidActionArchiveException ex)
{ {
// Log the error and fail the PrepareActionsAsync Initialization. // Log the error and fail the PrepareActionsAsync Initialization.
@@ -1157,6 +1165,8 @@ namespace GitHub.Runner.Worker
// Allow up to 20 * 60s for any action to be downloaded from github graph. // Allow up to 20 * 60s for any action to be downloaded from github graph.
int timeoutSeconds = 20 * 60; int timeoutSeconds = 20 * 60;
try
{
while (retryCount < 3) while (retryCount < 3)
{ {
string requestId = string.Empty; string requestId = string.Empty;
@@ -1244,6 +1254,13 @@ namespace GitHub.Runner.Worker
await Task.Delay(backOff); await Task.Delay(backOff);
} }
} }
}
catch (Exception ex) when (!(ex is OperationCanceledException) && !executionContext.CancellationToken.IsCancellationRequested)
{
Trace.Error($"Failed to download archive '{downloadUrl}' after {retryCount + 1} attempts.");
Trace.Error(ex);
throw new FailedToDownloadActionException($"Failed to download archive '{downloadUrl}' after {retryCount + 1} attempts.", ex);
}
ArgUtil.NotNullOrEmpty(archiveFile, nameof(archiveFile)); ArgUtil.NotNullOrEmpty(archiveFile, nameof(archiveFile));
executionContext.Debug($"Download '{downloadUrl}' to '{archiveFile}'"); executionContext.Debug($"Download '{downloadUrl}' to '{archiveFile}'");
+19
View File
@@ -2556,6 +2556,25 @@ namespace GitHub.DistributedTask.WebApi
} }
} }
[Serializable]
public sealed class FailedToDownloadActionException : DistributedTaskException
{
public FailedToDownloadActionException(String message)
: base(message)
{
}
public FailedToDownloadActionException(String message, Exception innerException)
: base(message, innerException)
{
}
private FailedToDownloadActionException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
[Serializable] [Serializable]
public sealed class InvalidActionArchiveException : DistributedTaskException public sealed class InvalidActionArchiveException : DistributedTaskException
{ {
+2 -1
View File
@@ -198,7 +198,8 @@ namespace GitHub.Runner.Common.Tests.Worker
Func<Task> action = async () => await _actionManager.PrepareActionsAsync(_ec.Object, actions); Func<Task> action = async () => await _actionManager.PrepareActionsAsync(_ec.Object, actions);
//Assert //Assert
await Assert.ThrowsAsync<ActionNotFoundException>(action); var ex = await Assert.ThrowsAsync<FailedToDownloadActionException>(action);
Assert.IsType<ActionNotFoundException>(ex.InnerException);
var watermarkFile = Path.Combine(_hc.GetDirectory(WellKnownDirectory.Actions), ActionName, "main.completed"); var watermarkFile = Path.Combine(_hc.GetDirectory(WellKnownDirectory.Actions), ActionName, "main.completed");
Assert.False(File.Exists(watermarkFile)); Assert.False(File.Exists(watermarkFile));