Skip to content

Commit 5c72801

Browse files
committed
Merge branch 'main' of github.com:actions/runner into fhammerl/mock-update
2 parents beaa6fe + f2e210e commit 5c72801

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242

4343
runs-on: ${{ matrix.os }}
4444
steps:
45-
- uses: actions/checkout@v1
45+
- uses: actions/checkout@v2
4646

4747
# Build runner layout
4848
- name: Build & Layout Release

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292

9393
runs-on: ${{ matrix.os }}
9494
steps:
95-
- uses: actions/checkout@v1
95+
- uses: actions/checkout@v2
9696

9797
# Build runner layout
9898
- name: Build & Layout Release
@@ -525,4 +525,4 @@ jobs:
525525
upload_url: ${{ steps.createRelease.outputs.upload_url }}
526526
asset_path: ${{ github.workspace }}/linux-arm64-trimmedpackages.json
527527
asset_name: actions-runner-linux-arm64-${{ steps.releaseNote.outputs.version }}-trimmedpackages.json
528-
asset_content_type: application/octet-stream
528+
asset_content_type: application/octet-stream

src/Runner.Listener/JobDispatcher.cs

+32-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
using System.Collections.Concurrent;
33
using System.Collections.Generic;
44
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Text.RegularExpressions;
58
using System.Threading;
69
using System.Threading.Tasks;
710
using GitHub.DistributedTask.WebApi;
8-
using GitHub.Runner.Common.Util;
9-
using GitHub.Services.WebApi;
10-
using Pipelines = GitHub.DistributedTask.Pipelines;
11-
using System.Linq;
12-
using GitHub.Services.Common;
1311
using GitHub.Runner.Common;
12+
using GitHub.Runner.Common.Util;
1413
using GitHub.Runner.Sdk;
14+
using GitHub.Services.Common;
15+
using GitHub.Services.WebApi;
1516
using GitHub.Services.WebApi.Jwt;
17+
using Pipelines = GitHub.DistributedTask.Pipelines;
1618

1719
namespace GitHub.Runner.Listener
1820
{
@@ -34,6 +36,7 @@ public interface IJobDispatcher : IRunnerService
3436
// and the server will not send another job while this one is still running.
3537
public sealed class JobDispatcher : RunnerService, IJobDispatcher
3638
{
39+
private static Regex _invalidJsonRegex = new Regex(@"invalid\ Json\ at\ position\ '(\d+)':", RegexOptions.Compiled | RegexOptions.IgnoreCase);
3740
private readonly Lazy<Dictionary<long, TaskResult>> _localRunJobResult = new Lazy<Dictionary<long, TaskResult>>();
3841
private int _poolId;
3942

@@ -964,6 +967,30 @@ private async Task LogWorkerProcessUnhandledException(IJobServer jobServer, Pipe
964967
TimelineRecord jobRecord = timeline.Records.FirstOrDefault(x => x.Id == message.JobId && x.RecordType == "Job");
965968
ArgUtil.NotNull(jobRecord, nameof(jobRecord));
966969

970+
try
971+
{
972+
if (!string.IsNullOrEmpty(errorMessage) &&
973+
message.Variables.TryGetValue("DistributedTask.EnableRunnerIPCDebug", out var enableRunnerIPCDebug) &&
974+
StringUtil.ConvertToBoolean(enableRunnerIPCDebug.Value))
975+
{
976+
// the trace should be best effort and not affect any job result
977+
var match = _invalidJsonRegex.Match(errorMessage);
978+
if (match.Success &&
979+
match.Groups.Count == 2)
980+
{
981+
var jsonPosition = int.Parse(match.Groups[1].Value);
982+
var serializedJobMessage = JsonUtility.ToString(message);
983+
var originalJson = serializedJobMessage.Substring(jsonPosition - 10, 20);
984+
errorMessage = $"Runner sent Json at position '{jsonPosition}': {originalJson} ({Convert.ToBase64String(Encoding.UTF8.GetBytes(originalJson))})\n{errorMessage}";
985+
}
986+
}
987+
}
988+
catch (Exception ex)
989+
{
990+
Trace.Error(ex);
991+
errorMessage = $"Fail to check json IPC error: {ex.Message}\n{errorMessage}";
992+
}
993+
967994
var unhandledExceptionIssue = new Issue() { Type = IssueType.Error, Message = errorMessage };
968995
unhandledExceptionIssue.Data[Constants.Runner.InternalTelemetryIssueDataKey] = Constants.Runner.WorkerCrash;
969996
jobRecord.ErrorCount++;

src/Runner.Listener/Runner.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ private async Task<int> RunAsync(RunnerSettings settings, bool runOnce = false)
318318

319319
IJobDispatcher jobDispatcher = null;
320320
CancellationTokenSource messageQueueLoopTokenSource = CancellationTokenSource.CreateLinkedTokenSource(HostContext.RunnerShutdownToken);
321-
321+
322322
// Should we try to cleanup ephemeral runners
323323
bool runOnceJobCompleted = false;
324324
try
@@ -425,6 +425,7 @@ private async Task<int> RunAsync(RunnerSettings settings, bool runOnce = false)
425425
}
426426
else
427427
{
428+
Trace.Info($"Received job message of length {message.Body.Length} from service, with hash '{IOUtil.GetSha256Hash(message.Body)}'");
428429
var jobMessage = StringUtil.ConvertFromJson<Pipelines.AgentJobRequestMessage>(message.Body);
429430
jobDispatcher.Run(jobMessage, runOnce);
430431
if (runOnce)
@@ -546,7 +547,7 @@ private void PrintUsage(CommandSettings command)
546547
_term.WriteLine($@" --windowslogonaccount string Account to run the service as. Requires runasservice");
547548
_term.WriteLine($@" --windowslogonpassword string Password for the service account. Requires runasservice");
548549
#endif
549-
_term.WriteLine($@"
550+
_term.WriteLine($@"
550551
Examples:
551552
Check GitHub server network connectivity:
552553
.{separator}run.{ext} --check --url <url> --pat <pat>

src/Runner.Worker/Worker.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using GitHub.Services.WebApi;
1010
using GitHub.Runner.Common;
1111
using GitHub.Runner.Sdk;
12+
using System.Text;
1213

1314
namespace GitHub.Runner.Worker
1415
{
@@ -43,6 +44,7 @@ public async Task<int> RunAsync(string pipeIn, string pipeOut)
4344
ArgUtil.NotNullOrEmpty(pipeOut, nameof(pipeOut));
4445
VssUtil.InitializeVssClientSettings(HostContext.UserAgents, HostContext.WebProxy);
4546
var jobRunner = HostContext.CreateService<IJobRunner>();
47+
var terminal = HostContext.GetService<ITerminal>();
4648

4749
using (var channel = HostContext.CreateService<IProcessChannel>())
4850
using (var jobRequestCancellationToken = CancellationTokenSource.CreateLinkedTokenSource(HostContext.RunnerShutdownToken))
@@ -64,7 +66,22 @@ public async Task<int> RunAsync(string pipeIn, string pipeOut)
6466
Trace.Info("Message received.");
6567
ArgUtil.Equal(MessageType.NewJobRequest, channelMessage.MessageType, nameof(channelMessage.MessageType));
6668
ArgUtil.NotNullOrEmpty(channelMessage.Body, nameof(channelMessage.Body));
67-
var jobMessage = StringUtil.ConvertFromJson<Pipelines.AgentJobRequestMessage>(channelMessage.Body);
69+
Pipelines.AgentJobRequestMessage jobMessage = null;
70+
try
71+
{
72+
jobMessage = StringUtil.ConvertFromJson<Pipelines.AgentJobRequestMessage>(channelMessage.Body);
73+
}
74+
catch (JsonReaderException ex)
75+
{
76+
if (channelMessage.Body.Length > ex.LinePosition + 10)
77+
{
78+
var errorChunk = channelMessage.Body.Substring(ex.LinePosition - 10, 20);
79+
terminal.WriteError($"Worker received invalid Json at position '{ex.LinePosition}': {errorChunk} ({Convert.ToBase64String(Encoding.UTF8.GetBytes(errorChunk))})");
80+
}
81+
82+
throw;
83+
}
84+
6885
ArgUtil.NotNull(jobMessage, nameof(jobMessage));
6986
HostContext.WritePerfCounter($"WorkerJobMessageReceived_{jobMessage.RequestId.ToString()}");
7087

0 commit comments

Comments
 (0)