Skip to content

A startup timeout loses its diagnostics when the CLI proxy log overflows the capture limit #76449

Done

Description

@soarkit

Summary

When the CLI proxy does not become ready within the startup timeout and the container produced more than the diagnostic capture limit, the readiness message itself is lost. The capture stops reading at MAX_DIAGNOSTIC_BYTES + 1, so the timeout line written afterwards never reaches the buffer; the EXIT trap then sees a full buffer and replaces all diagnostics with a generic "withheld because of the capture limit" error. The CI log therefore contains neither the timeout reason nor the container output that would explain it.

Actual behavior

The startup path captures container output through a bounded capture:

docker logs "$container" 2>&1 | head -c $((MAX_DIAGNOSTIC_BYTES + 1))

Once that many bytes have been read, head closes the pipe, so anything written to the capture afterwards is discarded. The readiness failure is reported after the dump:

echo "::error::CLI proxy failed to start within 30s"

That line is therefore written into a capture that has already stopped reading. The EXIT trap then inspects the captured file, finds it at the limit, and withholds the whole buffer:

# diagnostics withheld: capture exceeded MAX_DIAGNOSTIC_BYTES

Observed effect, with a small-log control:

  • with a 2 KB log, the readiness reason is reported normally;
  • with a 1.1 MB log, the readiness error is missing entirely and the only emitted message is the generic capture-limit error.

So the failure that matters most — a proxy that never became ready — is exactly the one whose reason disappears, and it disappears for two independent reasons at once: the timeout line is written after the capture has stopped, and the overflow path suppresses the rest of the buffer. The capture also runs before readiness is evaluated, which guarantees the dump happens even when its result will be unusable.

Consequences:

  • the CI log no longer states that the proxy timed out, so the failure reads as a diagnostics problem rather than a startup failure;
  • the container output that would show why it never became ready is withheld;
  • the same script succeeds with a smaller log, so the failure looks non-deterministic from the outside.

Expected behavior

On a readiness timeout, the CI log must contain the timeout reason, regardless of how much output the container produced, and the reason must not be replaced by a diagnostics-plumbing error. If the capture exceeds its limit, a bounded tail must still be published, and the truncation must be reported in addition to the timeout message rather than instead of it.

Reproduction

  1. Start the script against a container that emits more than MAX_DIAGNOSTIC_BYTES of output and never becomes ready.
  2. Let the readiness timeout expire.
  3. Observe that the "failed to start within 30s" error never appears; only the generic capture-limit withholding message is emitted.
  4. Repeat with a small log: the timeout error appears normally, confirming the loss depends on the capture size.

Root cause

The capture and the failure report are ordered so that the report lands after the reader has stopped. head -c terminates the stream at the limit, but the readiness error is appended to the same capture later, so it is written into a closed pipe and silently dropped. The overflow policy is then all-or-nothing: the EXIT trap re-reads the capture file, finds it at the limit, and withholds every diagnostic, including the ones collected before the limit was reached.

The two problems compound. Even if the timeout line were written before the capture filled, the withhold rule would still discard it; and even if the withhold rule kept a tail, the timeout line would still be missing because it is written after the reader exits. The current code has both conditions, which is why the reason disappears precisely for the largest logs.

Suggested fix

  • Emit the readiness error before or independently of the capture, so it cannot be dropped by a stopped reader.
  • Replace the all-or-nothing withhold with a bounded tail, so the last lines are always published and truncation is reported alongside them.
  • When the capture is truncated, print the withholding notice in addition to the failure reason, not as a replacement for it.

Add a test with output larger than the limit asserting that both the timeout message and the final log lines are present.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions