Skip to content

feat(woodpecker-agent): build the agent with retry window fixes - #43

Merged
slayerjain merged 3 commits into
mainfrom
fix/ci-agent-wide-kills-1104-next
Nov 6, 2026
Merged

slayerjain merged 3 commits into
mainfrom
fix/ci-agent-wide-kills-1104-next

Conversation

@slayerjain

Copy link
Copy Markdown
Member

Why

On 2026-11-04 Woodpecker agents canceled every workflow they were running, 63 in all, with every step marked killed and no step failing:

  • 43 were on three agents at 02:07-02:12 IST. The server had sent each of them a too_many_pings GOAWAY.
  • 20 were on one agent at 02:59-03:04 IST. Its connection to the server timed out, and the steps' end reports reached the server up to 2 minutes after the first one.

The cause is in the v3.20.1 agent (agent/rpc/client_grpc.go, retryRPC). It counts WOODPECKER_RETRY_TIMEOUT (2 minutes by default) from the moment an RPC began. Wait() stays open for the whole workflow, so once a workflow has run for 2 minutes, the first dropped connection gets no retry, and the runner cancels the workflow. Upstream has the issue (woodpecker-ci/woodpecker#7110) and an open fix (#7111), not yet in a release.

What

A new image, ghcr.io/keploy/keploy-ci:woodpecker-agent-<version>, built from keploy-ci-woodpecker-agent/:

  • It clones upstream at v3.20.1, checks that the tag still names commit 3f1bb0bd, and applies patches/.
  • 0001 is upstream's #7111 applied to v3.20.1, author kept. The window counts from the first failure of a streak, not from the start of the RPC. An attempt that stayed up for longer than the whole window starts a new streak.
  • 0002 adds tests for #7111:
    • a Wait() that outlived the window and then got the GOAWAY quoted below is retried. A second row does the same on the fake clock at production scale: a 2 minute window and a poll open for 30 minutes, past the backoff library's own 15 minute default limit;
    • a real outage still ends within the window;
    • an attempt that stayed up for 1.5 windows starts a new streak;
    • after an attempt that stayed up for 2 windows, the retry waits 10 ms, not an earlier streak's interval;
    • with WOODPECKER_RETRY_TIMEOUT=0 the interval keeps growing;
    • the agent gives up before a wait that would end past the window, not one interval later.
  • 0003 starts the window over once the agent has reconnected. With #7111 alone, a drop soon after a reconnection counted against the outage before it. A server that was down for 60 s, came back, and dropped the new connection 90 s later made the agent give up. So did drops after connections that each worked for less than the window, as in a GOAWAY storm.
    • The client counts the times its connection became Ready, from a goroutine that watches the connection's state and from every failed attempt.
    • gRPC reports Ready only after a new transport has completed its handshake with the server. So a count that moved between two failures proves the agent reconnected in between, and that failure starts a new window.
    • The interval keeps growing, so a server that accepts connections and drops them at once is not called every 10 ms.
    • Without a reconnection, the window keeps counting from the first failure, as with #7111.
  • The build runs the patched package's tests with -race and fails if any fails. The binary reports version 3.20.1-keploy.1.
  • The final image follows upstream's layout: scratch, CA certificates, timezone data, /etc/woodpecker, the same entrypoint, environment and healthcheck.
  • It is a standalone-images leg in docker-build.yml and publish.yml, amd64 only, since every Linux agent host is x86_64.

Tests

  • At v3.20.1, 0002's production-scale Wait() row fails with backoff: maximum elapsed time exceeded (last error: rpc error: code = Unavailable desc = closing transport due to: ... received prior goaway: code: ENHANCE_YOUR_CALM, debug data: "too_many_pings"). That is the agents' production log line.
  • 0003's rows run on the fake clock with a connection whose state the test sets:
    • the server restart above: retried;
    • drops after connections of 30 s, 60 s and 110 s, each reconnecting at once: all retried;
    • no reconnection, and one attempt that took 50 s to fail: the agent still gives up within the window;
    • a failure on a connection that stayed Ready, seen late by the watcher, does not start a new window;
    • a reconnection keeps the interval growing;
    • the watcher ends when the connection closes and when its context ends.
  • One more row runs a real gRPC connection against an in-memory server, stops the server and starts another: the client counts both connections.
  • With the patches, upstream's test-agent command passes: go test -race -cover -coverpkg=./... -timeout 60s -tags test ./cmd/agent ./agent/.... The new rows passed 30 runs in a row under -race.
  • Mutation testing: 32 mutants of the conditions in 0001 and 0003, each killed by a failing test. 28 fail the whole package suite. The other 4 make the retry loop never give up, so two wall-clock tests never end: v3.20.1's TestRetryRPCUnauthenticatedHonorsFiniteTimeout and #7111's TestRetryRPCGivesUpAfterWindow. With those two left out, each of the 4 is killed by a test on the fake clock.
  • Upstream's lint step (golangci/golangci-lint:v2.15.0, make lint) passes at v3.20.1. On the patched tree it reports 3 usetesting findings, all in tests that 0001 brings from #7111, none in 0002 or 0003.
  • The image builds for linux/amd64, its build-time tests pass, and woodpecker-agent --version prints 3.20.1-keploy.1.
  • docker-build.yml's static checks pass: one Go patch, no MinIO client, s3.sh parity, and only the base publishing latest.

Limits

  • A finite window rides out only outages well shorter than itself. When the agent gives up, the runner cancels every workflow on the agent. An outage longer than the window always ends that way, and the connection timeout above lasted close to the 2 minute default. A shorter outage can too:
    • While the connection is down, every RPC returns errNotConnected without calling the server, so the agent's retries do not bring the connection back. Only gRPC's reconnect backoff does: 1 s, growing 1.6x per attempt to 120 s, with about 20% jitter. Each connect attempt gets 20 s, or the current delay if that is longer. The connection can therefore return well after the server does.

    • The agent stops up to one retry interval (at most 15 s) before the window ends.

    • Measured on a real gRPC connection, against an in-memory server that refuses connections until it is back, 12 runs each:

      Window Outage Share of the window Runs that gave up
      2 min 60 s 50% 0 of 12
      2 min 72 s 60% 1 of 12
      2 min 90 s 75% 3 of 12
      2 min 108 s 90% 7 of 12
      6 s 3 s 50% 7 of 12
      6 s 3.6 s 60% 9 of 12 (5 of 6 in an earlier run)
    • gRPC's delays and the agent's interval do not shrink with the window, so a window of seconds does worse than these shares suggest. A finite window should be minutes long and about twice the longest outage to ride out. Otherwise use 0.

  • A server that keeps accepting connections and dropping them is retried without end, since every reconnection starts a new window. The interval grows to its 10 s cap.
  • The Ready count can miss a reconnection in two ways: a connection becomes Ready and drops again before the watcher goroutine runs, or the old connection drops and a new one becomes Ready between two reads of the state, which needs another workflow's RPC to reconnect before the woken watcher reads. Either way the failure after it counts against the window that was already running, as with #7111. A stats.Handler counting ConnBegin sees every new transport, so it would catch both. gRPC calls it before the server's handshake, though, so that count alone would also take a failed handshake for a reconnection.
  • With WOODPECKER_RETRY_TIMEOUT=0, which every agent runs, this image retries as v3.20.1 does: without end, at an interval that grows to its cap. An agent whose server is gone waits instead of exiting.
  • The macOS and Windows agents run the agent binary natively, so this image does not cover them. They stay on WOODPECKER_RETRY_TIMEOUT=0.
  • A workflow that reaches its repo's timeout still ends the same way: the Wait() deadline fires and the workflow is killed. That behaviour is expected and unchanged.

Rollout

Not rolled out to keploy's agents. They run WOODPECKER_RETRY_TIMEOUT=0, which retries forever, and they stay on it, so this image would change no retry behaviour for them. The image is built and published so it is ready if an agent ever needs a finite window, or until upstream ships the fix.

The v3.20.1 agent counts WOODPECKER_RETRY_TIMEOUT from the moment an RPC
began. Wait() stays open for the whole workflow, so the first dropped
connection after two minutes gets no retry and the agent cancels every
workflow it runs.

keploy-ci-woodpecker-agent builds upstream's v3.20.1 with upstream's open
fix (woodpecker-ci/woodpecker#7111, author kept) and three tests for the
failure as our agents hit it, runs the patched package's tests in the
build, and ships upstream's scratch layout. It is published as
ghcr.io/keploy/keploy-ci:woodpecker-agent-<version>, amd64 only.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
With upstream's fix alone, the window counted from the first failure of
a streak, and a streak ended only after an attempt that stayed up for
longer than the whole window. A drop soon after the agent had
reconnected still counted against the outage before it: a server down
for 60 s whose new connection dropped 90 s later, or drops after
connections that each worked for less than the window, made the agent
give up and cancel its workflows.

Patch 0003 counts the times the connection became Ready, from a
goroutine that watches its state and from every failed attempt. gRPC
reports Ready only after a new transport's handshake with the server,
so a count that moved between two failures proves a reconnection, and
that failure starts a new window. The interval keeps growing, so a
server that accepts connections and drops them at once is not called
every 10 ms.

Patch 0002 gains rows on the fake clock: a Wait() open for 30 minutes
under the default 2 minute window, past the backoff library's own
15 minute default, survives one drop; a real outage still ends within
the window; an attempt that stayed up for 1.5 windows starts a new
streak and resets the interval.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
The README advised a window longer than the outages to ride out, but an
outage well under the window can still end with the agent giving up.
While the connection is down the agent's retries do not reach the
server, so gRPC's reconnect backoff decides when the connection comes
back, and the agent stops up to one retry interval before the window
ends.

Say so, quote the measured rows, and advise a window of about twice the
longest outage, or 0. Say too that keploy's agents run 0 and that the
fixes matter for a finite window.

Signed-off-by: slayerjain <shubhamkjain@outlook.com>
@slayerjain
slayerjain merged commit 964f909 into main Nov 6, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant