mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 19:08:50 +00:00
## Summary - Fix Request.text() failure with "TypeError: undefined is not a function" after many requests on certain platforms - Set `#js_ref` in `Request.toJS()` for server-created requests, matching the existing pattern in `Response.toJS()` ## Root Cause When Request objects are created by the server (via `Request.init()`), the `#js_ref` field was never initialized. This caused `checkBodyStreamRef()` to fail silently when called in `toJS()` because `#js_ref.tryGet()` returned null. The bug manifested on macOS after ~4,500 requests when GC conditions were triggered, causing the weak reference lookup to fail and resulting in "TypeError: undefined is not a function" when calling `req.text()`. ## Fix The fix mirrors the existing pattern in `Response.toJS()`: 1. Create the JS value first via `js.toJSUnchecked()` 2. Set `#js_ref` with the JS wrapper reference 3. Then call `checkBodyStreamRef()` which can now properly access the JS value ## Test plan - [x] Added regression test that exercises Request.text() with 6000 requests and periodic GC - [x] Existing request tests pass - [x] HTTP server tests pass Fixes #26387 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1.4 KiB
1.4 KiB