Skip to content

ci: give Gradle two minutes to outlast a 429 in the android job - #342

Open
aimalygin wants to merge 1 commit into
mainfrom
claude/android-gradle-429-retry
Open

aimalygin wants to merge 1 commit into
mainfrom
claude/android-gradle-429-retry

Conversation

@aimalygin

Copy link
Copy Markdown
Owner

The android job now gives a refused repository request about two minutes of retries instead of three seconds, and checks that the Gradle it runs still has the setting that does this. One file changes, .github/workflows/ci.yml. Nothing about dependency verification changes: the job still resolves from an empty Gradle home with --dependency-verification strict.

Whether two minutes is enough for a real refusal by Maven Central is not known; see "Not verified".

What happened

Run 45272167046, job 138034512554 (2026-11-23, a pull request that touches nothing under platform/android): Build and verify Android AAR failed 18 seconds after Gradle started.

> Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:2.4.21.
   > Repository MavenRepo is disabled due to earlier error below:
      > Could not GET 'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/2.4.21/kotlin-gradle-plugin-2.4.21.pom'.
         > Received status code 429 from server: Too Many Requests
> There are 52 more failures with identical causes.

That POM is the first thing the build asks Maven Central for. So the runner's address was already limited before this job sent anything; the job's own volume did not trip the limit. Sonatype tracks its limits by the address or range it sees at its edge, and says of shared platforms that one user's traffic can be modest while the shared path as a whole still crosses the threshold (429 FAQ, shared egress, contacting support).

The other red android jobs of that day (runs 45265605767, 45235417813, 45171894098) are a compile error on a dependabot branch, not this.

What Gradle 9.8.1 does on a 429

Read from the classes of the 9.8.1 distribution the wrapper pins (javap on gradle-dependency-management-9.8.1.jar), then measured.

  • It retries. NetworkingIssueVerifier.isLikelyTransientNetworkingIssue counts as transient: HTTP 5xx, 408 and 429, SocketException, SocketTimeoutException, NoHttpResponseException, ConnectionClosedException. 401 and 403 are permanent.
  • Three tries in three seconds. ErrorHandlingModuleComponentRepository reads org.gradle.internal.repository.max.tentatives (default 3) and org.gradle.internal.repository.initial.backoff (default 1000 ms), and doubles the wait after each try. Measured: requests at 0.00 s, 1.02 s and 3.03 s.
  • Then the repository is disabled for the rest of the build. Every other module from it fails without a request being sent. That is the "52 more failures": the stand-in saw 3 requests in all.
  • Retry-After is ignored. A 429 with Retry-After: 10 was retried after 1.00 s.
  • org.gradle.internal.repository.max.retries does not exist in 9.8.1. That name also circulates for this setting, and the task for this PR started from it. No class in the distribution contains it, and setting it to 8 changed nothing (three tries, build failed). Gradle ignores a -D it does not know.
  • Neither property is documented. The 9.8.1 user guide pages on the build environment, networking, dependency caching and repository protocols do not mention them.

The options

Option Gets past a 429 when Cost
Gradle's own retry, more tries (this PR) the refusal ends within the budget One environment variable. Relies on an undocumented property, hence the check. A repository that is really down fails the job two minutes later than today.
A retry loop around gradlew the same condition, no better Shell in three places, one of them a script that also runs locally. Repeats every failure, a compile error included, unless it parses Gradle's output. Hides other flakiness.
Caching resolved artifacts between runs always, on a run that hits the cache: it asks Maven Central for nothing Removes a control. See below.

Chosen: Gradle's own retry. It covers 429, it repeats only the refused request, and it leaves everything else about the job as it is.

Why not the cache. It is the only option that does not depend on how long a refusal lasts, and it is what Sonatype asks of consumers. But the empty Gradle home in this job is deliberate. docs/verification.md: "A warm Gradle cache hides missing entries, so reproduce CI with a cold one". The v0.6 security review asks for it twice: IR-03 ("exercise it from a cold cache in CI") and IR-05 ("enforce cold-cache resolution in the blocking Android job"). Commit 150dc9d fixed exactly the kind of gap a warm cache had hidden. A cache would trade that for fewer requests, and that trade is not mine to make in a flake fix. If 429s turn out to outlast two minutes, the next step is that decision, not a larger number: for example a cache used only by pull request runs and keyed on every Gradle input, with main, tags, dispatches and the weekly run left cold.

Sonatype's FAQ also says that "the right answer is not to retry harder". This change adds at most five requests for one refused request, each further apart than the last.

The change

  • GRADLE_OPTS: -Dorg.gradle.internal.repository.max.tentatives=8 at job level. Eight tries wait 1, 2, 4, 8, 16, 32 and 64 seconds: 127 seconds for one request. It reaches all three Gradle runs of the job: the one inside scripts/build-android-adapter.sh and the two inline ones.
  • A step after the first build takes the property name out of GRADLE_OPTS and fails if the dependency-management JAR of the Gradle distribution the wrapper fetched does not contain it. Without it, a Gradle update that renames the property would bring the three-second limit back with nothing turning red.

Why eight: no source gives the length of a refusal, so this is a judgement. Two minutes costs nothing on a healthy run and little on a broken one.

What it leaves out

  • Local runs of scripts/build-android-adapter.sh and scripts/test-profile-import-jni.sh keep Gradle's default. They do not run from shared addresses, and a longer budget would make an offline laptop wait two minutes for an error. Setting GRADLE_OPTS by hand works there too.
  • No other workflow runs Gradle. The five release-evidence workflows contain no Gradle call; ci.yml's android job is the only one.
  • The supply-chain job. See "Not in this PR".

Verification

All on macOS arm64 with JDK 17 and the Gradle 9.8.1 distribution the wrapper fetches. The stand-in servers are short Python scripts; the first is in the fold at the end.

1. A toy project against a stand-in repository. Same shape as platform/android/build.gradle.kts: a root buildscript classpath, resolved while the project is configured. gradle help --no-daemon, empty Gradle home each time.

Stand-in answers 429 Setting Requests for the POM at Result
always default 0.00, 1.02, 3.03 s failed
first 2 requests default 0.00, 1.02, 3.03 s (200) passed
first 20 s default 0.00, 1.02, 3.03 s failed
first 20 s -D…max.tentatives=8 0, 1, 3, 7, 15, 31 s (200) passed
first 20 s GRADLE_OPTS with the same 0, 1, 3, 7, 15, 31 s (200) passed
first 20 s systemProp. line in the project's gradle.properties 0, 1, 3, 7, 15, 31 s (200) passed
first 20 s -D…max.retries=8 0.00, 1.01, 3.03 s failed
first request, Retry-After: 10 default 0.00, 1.00 s (200) passed

2. The real project. platform/android/gradlew -p platform/android help --dependency-verification strict --no-daemon with an empty Gradle home. A test-only init script, not part of this PR, pointed the Maven Central repository at a local stand-in that answers 429 for a while and then relays the real Maven Central; the bytes it relays still pass strict verification.

Stand-in answers 429 GRADLE_OPTS Result
first 20 s unset failed after 11 s, 3 requests. The message is the CI one word for word: Repository MavenRepo is disabled due to earlier error below, the same POM, There are 52 more failures with identical causes.
first 20 s as in the job BUILD SUCCESSFUL in 1m 3s. The POM was refused at 0, 1, 3, 7 and 15 s and served at 31 s; 207 requests answered 200 in all.
from 8 s to 28 s, in the middle of resolution unset failed, 39 more failures with identical causes
from 8 s to 28 s as in the job BUILD SUCCESSFUL in 1m 4s; one file refused 5 times, 207 requests answered 200 in all

3. The job's steps with the new environment. With GRADLE_OPTS exported as the job sets it: scripts/build-android-adapter.sh (native libraries reused, so its Gradle tasks were up to date), the new check, :xraymobile:testDebugUnitTest (242 tests, 34 skipped, none failed) and :xraymobile:lintDebug, each with --dependency-verification strict --no-daemon. All exit 0. Before that, without the variable, the same script passed from an empty Gradle home with all four ABIs built from source.

4. The new step. Its run block, taken out of the workflow file and run with bash -e and with bash -eo pipefail: exit 0 with the property the job sets; exit 1 with …max.retries; exit 1 with no distribution. The first pattern I wrote matched two JARs (gradle-dependency-management-serialization-codecs as well); this run caught it.

5. The script tests the rust job lists under Check repository scripts, with Python 3.12: bash -n over every script, the twelve scripts/tests/*.test.sh, the four unittest lines, both publish-migration-benchmarks.py verify runs, the two Python test scripts and the check-benchmark-publication.py run. All pass except check-benchmark-publication.test.sh, which fails at its malformed_path case on macOS. It fails the same way with main's ci.yml put back, and it does not read the workflow.

Not verified

  • A real 429. It cannot be produced on demand. Everything above is against stand-ins.
  • How long Maven Central refuses an address. Sonatype's pages say blocks are temporary and start short; none gives a duration. If a refusal outlasts 127 seconds the job fails exactly as before, only later.
  • Linux. The check ran under bash 3.2 with BSD unzip and grep. This PR's own android run is the first run of it on the runner.
  • A 429 from Google's repository or the plugin portal. The setting is per repository and applies to them too; only Maven Central was stood in for.

Not in this PR

  • scripts/check-gradle-verification.py --online, in the supply-chain job, has the same exposure and a misleading message. It fetches every pinned artifact from its canonical repository on every run, Maven Central for most, with curl --retry 3: about seven seconds of retries. When a checksum sidecar cannot be fetched it reports "canonical repository has no checksum sidecar" whatever the cause. Run 45171861093 (2026-11-23) failed that way on com.google.android:annotations:4.1.1.4, whose .sha1 sidecar Maven Central serves (200 when I asked). The log does not hold the HTTP status, so that it was a 429 is likely, not shown.
  • A caching proxy or mirror for Maven Central. What Sonatype and Gradle both recommend. It changes where artifacts come from, which is a larger decision than this fix.
The stand-in repository used for the toy project
#!/usr/bin/env python3
"""Stand-in Maven repository that answers 429 before it starts serving files.

--refuse-first K   the first K requests get 429
--refuse-for T     every request gets 429 until T seconds after the first one
Each request is logged as: seconds since the first request, method, path, status.
"""
import argparse
import http.server
import pathlib
import threading
import time

parser = argparse.ArgumentParser()
parser.add_argument("--root", required=True)
parser.add_argument("--port", type=int, required=True)
parser.add_argument("--log", required=True)
parser.add_argument("--refuse-first", type=int, default=0)
parser.add_argument("--refuse-for", type=float, default=0.0)
parser.add_argument("--retry-after", type=int, default=-1)
args = parser.parse_args()

root = pathlib.Path(args.root).resolve()
lock = threading.Lock()
state = {"first": None, "count": 0}
log = open(args.log, "w", buffering=1)


class Handler(http.server.BaseHTTPRequestHandler):
    protocol_version = "HTTP/1.1"

    def respond(self, send_body):
        with lock:
            now = time.monotonic()
            if state["first"] is None:
                state["first"] = now
            elapsed = now - state["first"]
            state["count"] += 1
            refused = state["count"] <= args.refuse_first or elapsed < args.refuse_for
        target = (root / self.path.lstrip("/")).resolve()
        if refused:
            status, body = 429, b"Too Many Requests\n"
        elif root in target.parents and target.is_file():
            status, body = 200, target.read_bytes()
        else:
            status, body = 404, b"Not Found\n"
        self.send_response(status)
        if status == 429 and args.retry_after >= 0:
            self.send_header("Retry-After", str(args.retry_after))
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        if send_body:
            self.wfile.write(body)
        log.write(f"{elapsed:7.2f}s {self.command:4} {self.path} -> {status}\n")

    def do_GET(self):
        self.respond(True)

    def do_HEAD(self):
        self.respond(False)

    def log_message(self, *_):
        pass


http.server.ThreadingHTTPServer(("127.0.0.1", args.port), Handler).serve_forever()

The toy project is a settings.gradle.kts with a project name and this build.gradle.kts, with demo:lib:1.0 served from the stand-in's directory as a minimal POM and JAR:

buildscript {
    repositories {
        maven {
            name = "StandIn"
            url = uri("http://127.0.0.1:${System.getenv("STANDIN_PORT")}/")
            isAllowInsecureProtocol = true
        }
    }
    dependencies {
        classpath("demo:lib:1.0")
    }
}

🤖 Generated with Claude Code

Maven Central rate-limits the addresses that GitHub's runners share. On
2026-11-23 the android job failed on it (run 45272167046): the first
request the build sent, for kotlin-gradle-plugin-2.4.21.pom, was answered
429, and the build had failed 18 seconds after it started.

Gradle 9.8.1 does retry a 429, as it does 408, 5xx and a dropped
connection, but three times in three seconds. Then it disables the
repository for the rest of the build, which is where "52 more failures
with identical causes" comes from. The number of tries is the internal
property org.gradle.internal.repository.max.tentatives, 3 by default,
and the wait doubles from one second. The job now sets it to 8 through
GRADLE_OPTS, which reaches all three Gradle runs of the job: 1+2+...+64
= 127 seconds for one request.

The job keeps resolving from an empty Gradle home. That is a control,
not an omission (docs/verification.md; IR-03 and IR-05 of the v0.6
security review), so a dependency cache was not an option here.

The property is undocumented and Gradle ignores a -D it does not know.
A step after the first build fails when the name is no longer in the
Gradle distribution the wrapper fetched, so a Gradle update cannot bring
the three-second limit back unnoticed.
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