Skip to content

ci: retry Spark download in site guide tests - #5812

Merged
MonkeyCanCode merged 3 commits into
apache:mainfrom
sririshindra:fix-site-guides-spark-download
Oct 24, 2026
Merged

MonkeyCanCode merged 3 commits into
apache:mainfrom
sririshindra:fix-site-guides-spark-download

Conversation

@sririshindra

@sririshindra sririshindra commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

The test-site-guides CI job downloads Spark 3.5.8 through the Apache mirror redirector (closer.lua, which redirects to dlcdn.apache.org) and pipes it into tar. On 2026-10-18 this job failed on two consecutive runs of an unrelated PR (#5721, spec-only) with:

gzip: stdin: not in gzip format
tar: Child returned status 1
subprocess.CalledProcessError: Command '[tar, --extract, --gunzip, ...]' returned non-zero exit status 2.

Failing runs/jobs:

The same job passed on other PRs/main earlier the same day and the day before (e.g. runs 39082544721, 38989844622, 39016950497), so this looks like a transient mirror/CDN problem: the download returned a small non-gzip body (about 452 bytes) rather than the tarball. I could not reproduce it locally; the redirect and the archive.apache.org copy both respond normally from my machine.

Current behavior: curl has no --fail and there is no retry, so one bad response from the mirror fails the whole job.

Change in site/it/site_checks/spark.py:

  • curl now uses --fail, so HTTP errors produce a non-zero exit instead of an error page being piped into tar.
  • The download and extract step is retried up to 5 times with exponential backoff (about 2s, 4s, 8s, 16s) and jitter, so concurrent CI jobs do not retry in lockstep. The whole curl | tar pipeline is retried, which also covers the case where the mirror returns a non-gzip body with a 200 status.

Assumptions:

  • The failure is transient and mirror-related rather than a permanent change to the Spark 3.5.8 location.
  • No checksum verification is added, to keep the change small (the existing flow has none); tar --gunzip already rejects non-gzip responses.

Tested: unit tests cover retry-until-success with backoff delays and giving up after the last attempt; pytest in site/it passes and ruff format/ruff check are clean. I also ran ensure_spark against a local HTTP server that returned a 503, then a non-gzip 200, then a valid tarball, and it succeeded on the third attempt. The CI-only change needs no CHANGELOG or site docs update.

Checklist

  • 🛡️ Don't disclose security issues! (contact [email protected])
  • 🔗 Clearly explained why the changes are needed, or linked related issues
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (if needed) - not needed, CI-only
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed) - not needed, CI-only

The guide tests download Spark through the Apache mirror redirector. When the
mirror/CDN returns a small non-gzip response, the test run fails with
'gzip: stdin: not in gzip format'. Fail curl on HTTP errors, retry, and fall
back to archive.apache.org when the default download URL fails.
@MonkeyCanCode

Copy link
Copy Markdown
Contributor

Hello @sririshindra,

Thanks for the PR. However, I think this change is intentional: #2038

Thanks,
Yong

@ayushtkn ayushtkn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the policy we "must" use closer.lua only
https://infra.apache.org/release-download-pages.html#download-scripts

but adding retry maybe to all such commands looks fair enough to me

Comment thread site/it/site_checks/spark.py Outdated
curl_cmd = ["curl", "--location", spark_tarball_url]
urls = [spark_tarball_url]
if spark_tarball_url == SPARK_TGZ_URL:
urls.append(SPARK_TGZ_FALLBACK_URL)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic looks pretty complicated to me. Would adding retries to the curl command above not be sufficient?

@sririshindra sririshindra Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe retries is the best way to go. Let me add retries with staggered exponetial backoff and hopefully that is enough to solve the transient failures. Let me update the PR.

@MonkeyCanCode MonkeyCanCode Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

… to another URL

Replace the fallback-URL logic with a simple retry of the whole download and extract step, backing off exponentially with jitter between attempts.

@orca-review-bot orca-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

AI-generated review. Written by an agent. It can be wrong, so please push back where it is.

Nice fix. Retrying the whole curl | tar pipeline is the right call, since curl's --retry wouldn't catch the 200-with-non-gzip-body case you actually hit. The loop logic and the backoff tests look correct.

A few non-inline things:

  • Every failure the tests simulate comes from tar. Can we add one to site/it/test/test_spark.py where curl exits non-zero (e.g. FakeProc(22, stdout=FakeStdout())) and the next attempt succeeds?
  • The first commit had an archive.apache.org fallback that the second commit dropped. Was that requested? All five retries go back to the same closer.lua URL within about 30s, so an outage lasting a few minutes will still fail the job.
  • Small one: can we retitle to Conventional Commits (e.g. ci: retry Spark download in site guide tests) and drop the empty Fixes #?

No CHANGELOG or docs update needed for this.

Comment thread site/it/site_checks/spark.py Outdated


def _download_and_extract(url: str, spark_dir: Path) -> None:
curl_cmd = ["curl", "--location", "--fail", url]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the mirror stalls instead of erroring, curl just sits there and the retry loop never kicks in. The job hangs until the Actions timeout. Can we add something like --connect-timeout 30 --speed-limit 1024 --speed-time 60 here so a stalled download fails fast and gets retried?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added --connect-timeout 30 --speed-limit 1024 --speed-time 60 so a stalled download fails and gets retried.

Comment thread site/it/site_checks/spark.py Outdated
f"Downloading Spark failed ({e}), retrying in {delay:.1f}s (attempt {attempt}/{DOWNLOAD_ATTEMPTS})..."
)
time.sleep(delay)
print("::endgroup::")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With line 57, if we exhausted all of the retry, it will raise and halt the script. In this case, line 65 is never print. Should we wrap this in a finally clause?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. The retry loop is now wrapped in try/finally, so ::endgroup:: is always printed. Added a test for it.

Add curl connect and stall timeouts so a hung mirror fails fast and is
retried, always close the log group when all attempts fail, and cover
curl failures in the tests.
@sririshindra sririshindra changed the title Make site guide tests resilient to failed Spark downloads ci: retry Spark download in site guide tests Oct 22, 2026
@sririshindra

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews. I pushed an update:

  • Added curl connect/stall timeouts so a hung mirror is retried instead of hanging the job.
  • ::endgroup:: is now always printed, including when all attempts fail.
  • Added a test where curl exits non-zero and the next attempt succeeds.
  • Retitled the PR and dropped the empty Fixes #.

I did not restore the archive.apache.org fallback: the ASF download policy requires closer.lua (link), and review feedback preferred keeping this simple. Retries with backoff are what remains.

@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Oct 22, 2026
@MonkeyCanCode

Copy link
Copy Markdown
Contributor

LGTM, thanks for the fix @sririshindra.

@flyrain flyrain left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 Thanks @sririshindra !

@MonkeyCanCode
MonkeyCanCode merged commit 4406907 into apache:main Oct 24, 2026
24 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board Oct 24, 2026
@MonkeyCanCode

Copy link
Copy Markdown
Contributor

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.

7 participants