Skip to content

[BUG] Premature close during deploy on the worker-versions endpoint #1296

Description

@alex-all3dp

Describe the bug

After #1291 (in 1.20.0) fixed the Premature close failures from #1285 by setting Accept-Encoding: identity on the R2 provisioning client, the same truncated-gzip failure now surfaces one step later in opennextjs-cloudflare deploy, when it queries GET /workers/scripts/{script}/versions.
The R2 fix is working (provisioning/cache population succeed) but this following SDK call still accepts gzip and crashes on a truncated body.

Crash logs:


┌──────────────────────────────┐
│ OpenNext — Cloudflare deploy │
└──────────────────────────────┘

Monorepo detected at /home/runner/work/craftcloud-client/craftcloud-client

Populating remote R2 incremental cache...
Monorepo detected at /home/runner/work/craftcloud-client/craftcloud-client
(node:3112) [DEP0190] DeprecationWarning: Passing args to a child process
with shell option true can lead to security vulnerabilities, as the arguments
are not escaped, only concatenated.
(Use `node --trace-deprecation ...` to show where the warning was created)
Using "CF_ACCOUNT_ID" environment variable. This is deprecated. Please use
"CLOUDFLARE_ACCOUNT_ID", instead.
  4%|█                                            | 1/25 [00:00:<00:00:,
0.00it/s]  8%|███                                          | 2/25
[00:00:<00:00:, 400.00it/s] 12%|█████
| 3/25 [00:00:<00:00:, 500.00it/s] 16%|███████
| 4/25 [00:00:<00:00:, 571.43it/s] 20%|█████████
| 5/25 [00:00:<00:00:, 625.00it/s] 24%|██████████
| 6/25 [00:00:<00:00:, 750.00it/s] 28%|████████████
| 7/25 [00:00:<00:00:, 777.78it/s] 32%|██████████████
| 8/25 [00:00:<00:00:, 800.00it/s] 36%|████████████████
| 9/25 [00:00:<00:00:, 900.00it/s] 40%|██████████████████
| 10/25 [00:00:<00:00:, 909.09it/s] 44%|███████████████████
| 11/25 [00:00:<00:00:, 916.67it/s] 48%|█████████████████████
| 12/25 [00:00:<00:00:, 1000.00it/s] 52%|███████████████████████
| 13/25 [00:00:<00:00:, 1083.33it/s] 56%|█████████████████████████
| 14/25 [00:00:<00:00:, 1076.92it/s] 60%|███████████████████████████
| 15/25 [00:00:<00:00:, 1153.85it/s] 64%|████████████████████████████
| 16/25 [00:00:<00:00:, 1142.86it/s] 68%|██████████████████████████████
| 17/25 [00:00:<00:00:, 1214.29it/s] 72%|████████████████████████████████
| 18/25 [00:00:<00:00:, 1200.00it/s]
76%|██████████████████████████████████           | 19/25 [00:00:<00:00:,
1266.67it/s] 80%|████████████████████████████████████         | 20/25
[00:00:<00:00:, 1333.33it/s] 84%|█████████████████████████████████████
| 21/25 [00:00:<00:00:, 1312.50it/s]
88%|███████████████████████████████████████      | 22/25 [00:00:<00:00:,
1375.00it/s] 92%|█████████████████████████████████████████    | 23/25
[00:00:<00:00:, 1437.50it/s]
96%|███████████████████████████████████████████  | 24/25 [00:00:<00:00:,
1411.76it/s]100%|█████████████████████████████████████████████| 25/25
[00:00:<00:00:, 1470.59it/s]
Successfully populated cache with 25 entries
Tag cache does not need populating

/home/runner/work/craftcloud-client/craftcloud-client/node_modules/node-fetch/lib/index.js:400
				reject(new FetchError(`Invalid response body while trying to fetch
${_this4.url}: ${err.message}`, 'system', err));
				       ^
FetchError: Invalid response body while trying to fetch
https://api.cloudflare.com/client/v4/accounts/62d5862473ac28e692dfb93777cf3e0d/workers/scripts/craftcloud-stg/versions:
Premature close
    at Gunzip.<anonymous> (/home/runner/work/craftcloud-client/craftcloud-client/node_modules/node-fetch/lib/index.js:400:12)
    at Gunzip.emit (node:events:521:24)
    at Gunzip.emit (node:domain:489:12)
    at emitErrorNT (node:internal/streams/destroy:170:8)
    at emitErrorCloseNT (node:internal/streams/destroy:129:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
  type: 'system',
  errno: 'ERR_STREAM_PREMATURE_CLOSE',
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}

Node.js v24.17.0

Steps to reproduce

  1. A Next.js app configured for @opennextjs/cloudflare 1.20.0 with the R2 incremental cache enabled (r2IncrementalCache), deployed to a Workers script.
  2. Run opennextjs-cloudflare deploy (we use deploy --minify)
  3. The deploy provisions/populates the remote R2 incremental cache (this now succeeds, thanks to fix: disable compression for R2 provisioning #1291), then queries the worker versions endpoint GET /workers/scripts/{script}/versions via the cloudflare SDK.
  4. Intermittently, that fetch crashes with ERR_STREAM_PREMATURE_CLOSE and the process exits non-zero, failing the deploy.

Expected behavior

opennextjs-cloudflare deploy completes successfully. A transient/truncated gzip response from the Cloudflare API on the worker-versions query is tolerated the same way the R2 provisioning call now tolerates it after #1291, i.e. the client requests an uncompressed response (Accept-Encoding: identity) and/or retries, rather than crashing the process and failing the deploy.

@opennextjs/cloudflare version

1.2.0

Wrangler version

4.104.0

next info output

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.5.0: Mon Apr 27 20:39:29 PDT 2026; root:xnu-12377.121.6~2/RELEASE_ARM64_T8142
  Available memory (MB): 24576
  Available CPU cores: 10
Binaries:
  Node: 24.16.0
  npm: 11.13.0
  Yarn: N/A
  pnpm: 11.9.0
Relevant Packages:
  next: 16.2.9 // Latest available version is detected (16.2.9).
  eslint-config-next: N/A
  react: 19.2.7
  react-dom: 19.2.7
  typescript: 6.0.3

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions