Skip to content

fix(fetch-engine): retry engine download when the connection resets mid-download - #31371

Open
mia03ther wants to merge 1 commit into
prisma:v7from
mia03ther:fix/31364
Open

mia03ther wants to merge 1 commit into
prisma:v7from
mia03ther:fix/31364

Conversation

@mia03ther

@mia03ther mia03ther commented Dec 5, 2026 •

Copy link
Copy Markdown

Fixes #31364

Summary

downloadZip ran the download inside an async Promise executor that
awaited the hash promises. When the response stream aborted mid-download
(e.g. ECONNRESET), hasha.fromStream rejected inside that executor, so
the rejection never reached reject and became an unhandled rejection.
Node terminated the process on the first attempt, before p-retry could
retry, and before the postinstall's .catch() could swallow it — even
with failSilent: true.

This removes the async executor and routes hash failures through
reject via Promise.all(...).then(..., reject), so the error reaches
p-retry and the download is retried as RETRIES_COUNT intends. If all
retries fail, the error now propagates normally instead of crashing the
process.

Test plan

  • Added packages/fetch-engine/src/__tests__/downloadZip.test.ts with a
    mocked node-fetch (no network): a happy-path download with real gzip
    • checksum verification, and a mid-download ECONNRESET case asserting
      the promise rejects and the engine URL is fetched 3 times (1 + 2 retries).
  • pnpm --filter @prisma/fetch-engine equivalent run locally via vitest:
    2 passed. Against the old code the same test reports 3 unhandled
    rejections (ECONNRESET, attemptNumber: 3), reproducing @prisma/engines postinstall crashes on ECONNRESET instead of retrying (unhandled rejection in downloadZip) #31364.
  • eslint clean on both changed files. Full download.test.ts suite not
    run locally (downloads real engines from the network); CI to cover.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of download interruptions and checksum-validation failures, so errors are reported through the download retry process.
    • Downloads that are interrupted by a connection reset now fail with a clear aborted-download error after retries.
  • Tests

    • Added coverage for successful ZIP downloads, including file contents, modification time, and checksum validation, as well as interrupted downloads.

…id-download

The download ran inside an async Promise executor that awaited the
hash promises. A rejection there (e.g. ECONNRESET aborting the response
stream mid-download) never reached `reject` and became an unhandled
rejection, crashing the process before p-retry could retry.

Route hash failures through `reject` instead, so the error reaches
p-retry and the download is retried as RETRIES_COUNT intends.

Fixes prisma#31364
@coderabbitai

coderabbitai Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

downloadZip now forwards hash-promise failures to its rejection path. Tests cover a successful download and a connection reset that rejects after three engine fetch attempts.

Changes: Download error handling

Layer / File(s) Summary
Forward hash failures and test download behavior
packages/fetch-engine/src/downloadZip.ts, packages/fetch-engine/src/__tests__/downloadZip.test.ts
The Promise executor is no longer async. Hash promise failures are forwarded to reject, while checksum mismatch rejections remain. Tests check successful download metadata and file contents, and verify that a connection reset rejects after three engine requests.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: dulmandakh

Merge Risk: Minimal · up to d9d66

Engine downloads that are interrupted by a connection reset can now be retried as configured instead of crashing with an unhandled rejection. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the fix and its trigger: a retry of the engine download when the connection resets mid-download. The change removes the async Promise executor in downloadZip and routes hash-promise fa…
Linked Issues check Passed [#31364] requires that a connection reset during engine download be retried under RETRIES_COUNT. At the reviewed head, downloadZip.ts no longer wraps the download in an async Promise executor. The h…
Out of Scope Changes check Passed The changes are limited to packages/fetch-engine/src/downloadZip.ts and the new test file packages/fetch-engine/src/__tests__/downloadZip.test.ts. The downloadZip.ts change removes the async exe…
Full details: Title check

Explanation

The title names the fix and its trigger: a retry of the engine download when the connection resets mid-download. The change removes the async Promise executor in downloadZip and routes hash-promise failures through reject, so ECONNRESET errors reach p-retry. The title matches the main change, and the title is in the conventional fix(scope) form.

Full details: Linked Issues check

Explanation

[#31364] requires that a connection reset during engine download be retried under RETRIES_COUNT. At the reviewed head, downloadZip.ts no longer wraps the download in an async Promise executor. The hash promises (hashPromise, zippedHashPromise) are now consumed by Promise.all([...]).then(..., reject), so a hash rejection reaches reject. The outer retry(..., { retries: RETRIES_COUNT }) therefore sees the error. response.body errors also still call reject directly. The new test downloadZip.test.ts covers a mid-download ECONNRESET and expects three fetch attempts. The author reports that this test passed locally and that it reproduced the unhandled rejection on the old code. The second expectation in #31364, silent failure under failSilent: true after retries are exhausted, depends on existing postinstall .catch() handling. That handling was not inspected in this review. This PR does not claim to implement it, and the PR objectives state that the exhausted-retry error propagates normally.

Full details: Out of Scope Changes check

Explanation

The changes are limited to packages/fetch-engine/src/downloadZip.ts and the new test file packages/fetch-engine/src/__tests__/downloadZip.test.ts. The downloadZip.ts change removes the async executor and routes hash failures through reject. This directly implements the #31364 retry fix. The checksum comparison logic is preserved and now runs inside the .then callback. The test file supports that fix by covering the happy path and the ECONNRESET retry path. No unrelated changes were identified. The diff tool was unavailable, so the base-to-head comparison was made from the reviewed head file and the PR summary, not from a read diff.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: prisma/orm
  • Branch: v7
  • File: .coderabbit.yml
  • Commit: 92d8025
  • Layers: Repository YAML
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: d183093f-2f3d-4ff6-b9b8-9450644ba67c
Commits

Reviewing files that changed from the base of the PR and between 92d8025 and d9d6634.

Files selected for processing: 2

  • packages/fetch-engine/src/__tests__/downloadZip.test.ts
  • packages/fetch-engine/src/downloadZip.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

This branch has not been deployed

No deployments
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