🐛 BUG: getPlatformProxy R2 body stream fails under Bun: responseDispatcher.close is not a function

Open
#17,169 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
backend, testing

Research direction

Start with the synchronous-fetch worker in miniflare's dist/src/index.js, where the issue reports responseDispatcher.close() is called after a ReadableStream result. Reproduce with the provided three-file setup under Bun using bun install && bun t.ts, then compare with Node. Done when the R2 body stream reads successfully under Bun and the existing Node behavior still works.

Written by the indexing model from the issue text.

Description

What versions & operating system are you using?
  • wrangler 4.168.0 (miniflare 5.20261123.1-beta); also reproduces on wrangler 4.165.0 (miniflare 5.20261118.0-beta)
  • Bun 1.4.2
  • Linux 6.12 (Debian 13, x86_64)
  • Works under Node 22.23.5 with the same files
Please provide a link to a minimal reproduction

Inline, three files in an empty directory:

package.json

{ "name": "r2t", "private": true, "dependencies": { "wrangler": "4.168.0" } }

wrangler.jsonc

{ "name": "r2t", "main": "w.js", "compatibility_date": "2026-11-01", "r2_buckets": [{ "binding": "B", "bucket_name": "test-bucket" }] }

w.js

export default {}

t.ts

import { getPlatformProxy } from "wrangler";
const p = await getPlatformProxy<{ B: any }>({ persist: false });
await p.env.B.put("k", "hello stream");
const o = await p.env.B.get("k");
try { console.log("streamed:", await new Response(o.body).text()); } catch (e) { console.log("FAIL:", (e as Error).stack); }
await p.dispose();

Run bun install && bun t.ts. Under Node (node t.mts, same code without the type annotations) it prints streamed: hello stream.

Describe the Bug

Reading an R2 object's body stream through getPlatformProxy fails under Bun. arrayBuffer() / text() on the same object work, so only the ReadableStream result path is affected.

The cause looks like the synchronous-fetch worker in miniflare's dist/src/index.js: after a ReadableStream result it retires the pool with void responseDispatcher.close().catch(() => {}). Under Bun, the undici Pool it creates has no close() method, so this throws a TypeError synchronously. The .catch doesn't help because the call itself throws before a promise exists. Guarding the call (responseDispatcher?.close?.()), or wrapping it in a try/catch, would probably be enough.

Please provide any relevant error logs
FAIL: TypeError: responseDispatcher.close is not a function. (In 'responseDispatcher.close()', 'responseDispatcher.close' is undefined)
    at <anonymous> (blob:edf7a7d1-1ecf-46e0-9398-0c83d7a44270:47:31)
Dominant language
TypeScript
Stars
4.7k
Forks
1.7k
Avg merge
1d 22h
Merged PRs (30d)
282

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/workers-sdk

All issues in cloudflare/workers-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.