This change completes the refactor by removing all transitional and temporary
code that was left over from the migration process.
Changes:
- Removed local boolean flag variables (is_waiting_*) - replaced with direct state checks
- Merged clearData() into deinit() - single unified cleanup path
- Removed transitional helper methods (lockShared, assertMainThread from FetchTasklet)
- Updated 13 call sites to use direct field access (this.shared.lock())
- Net reduction of 31 lines
Verification:
- No boolean flags remain (only 2 comment references)
- No clearData() function remains
- No transitional helpers remain in FetchTasklet struct
- Build succeeds: bun bd ✅
- Tests passing: 7/8 fetch tests pass (1 pre-existing failure)
The refactor is now complete with zero vestigial code remaining.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This change consolidates error storage into a single FetchError union field
while maintaining backward compatibility with existing error handling code.
Changes:
- Added fetch_error: FetchError field to MainThreadData
- Updated 5 error creation sites to populate unified FetchError union
- Abort signal callbacks → .abort_error variant
- TLS certificate errors → .js_error variant
- Request write errors → .js_error variant
- Added fetch_error.deinit() to MainThreadData cleanup
- Preserved old error fields (abort_reason, result.fail) for compatibility
This non-breaking change sets up the new error infrastructure alongside
existing error handling. Future cleanup will migrate error retrieval and
remove old fields.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This change refactors complex nested conditional logic in onBodyReceived into
clean state-based dispatch, improving readability and maintainability.
Changes:
- Replaced ~160 lines of nested if-else chains with 57-line state machine
- Added handleBodyError() for centralized error handling
- Integrated existing helper functions via lifecycle state dispatch:
- processBodyDataInitial() for .http_receiving_body state
- streamBodyToJS() for .response_body_streaming state
- bufferBodyData() for .response_body_buffering state
- Simplified buffer management using explicit state checks
- 65% code reduction in onBodyReceived function
The state machine provides single source of truth for body handling, with clear
separation of concerns and no duplicated logic.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This change wraps resources in RAII ownership types to enforce explicit
ownership tracking and automatic cleanup.
Changes:
- Applied RequestHeaders wrapper: Enforces ownership tracking via private field
- Applied ResponseMetadataHolder wrapper: Explicit take semantics prevent double-free
- Added helper methods: hasMetadata(), borrowMetadata() for non-destructive access
- Updated all creation and usage sites
- Removed manual cleanup code (now handled by wrapper deinit())
Deferred for future phases:
- HTTPRequestBodyV2: Planned for Phase 3, Step 3.4
- AbortHandling: Requires additional field migration first
- url_proxy_buffer: Current manual pattern is clear and simple
All applied wrappers use private fields to prevent incorrect usage and ensure
single cleanup paths.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This change implements proper mutex locking for all shared data accesses,
eliminating race conditions between the HTTP thread and main thread.
Changes:
- Added RAII locked access to 11 functions accessing shared data
- Implemented copy-out pattern to minimize lock holding time
- Fixed field access paths discovered during implementation
- Verified finalizer race protection (already correct)
- Verified cross-thread deallocation handling (already correct)
- Verified HTTP callback locking (already correct)
All concurrent accesses now properly synchronized. Main thread and HTTP thread
can safely access shared state without data races.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This change completes the migration of FetchTasklet fields to MainThreadData
and SharedData structs, eliminating duplicate field storage and clarifying
data ownership and thread safety boundaries.
Changes:
- Removed 27 duplicate fields from FetchTasklet struct
- Updated 100+ access sites to use this.main_thread.X or this.shared.X
- Main thread fields: promise, global_this, vm, response, streams, abort handling
- Shared fields: HTTP client, buffers, result, metadata, ref_count, mutex
- Net reduction of 61 lines of code
All data now explicitly separated into main-thread-only and thread-safe zones,
providing clear boundaries for concurrent access patterns.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This change replaces boolean state flags with state machine checks, eliminating
scattered flag management and improving code clarity.
Changes:
- Removed is_waiting_request_stream_start flag
→ Replaced with request_stream_state == .waiting_start checks
- Removed is_waiting_abort flag
→ Replaced with abort_requested atomic loads
- Removed ignore_data flag
→ Replaced with shouldIgnoreBodyData() helper calls
- Fixed 4 broken this.lifecycle accesses to use this.shared.lifecycle
- Added proper mutex locking for lifecycle transitions in toResponse()
All state tracking now goes through the FetchLifecycle and RequestStreamState
enums, providing clear state transitions and better thread safety.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
This change introduces MainThreadData and SharedData struct instances to
FetchTasklet alongside existing fields, without changing behavior. This
establishes the foundation for gradual migration to thread-safe data access.
Changes:
- Added main_thread: MainThreadData field (inline storage)
- Added shared: *SharedData field (heap-allocated)
- Added lockShared() and assertMainThread() helper methods
- Initialized both fields in get() function
- Added proper cleanup in clearData()
All existing fields remain unchanged - this is a non-breaking change that
enables incremental migration in subsequent steps.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add lifecycle and request_stream_state fields to SharedData struct with
proper default values. This is a non-breaking change that introduces the
new state machine alongside existing boolean flags.
Added:
- lifecycle: FetchLifecycle = .created (in SharedData)
- request_stream_state: RequestStreamState = .none (in SharedData)
All existing boolean flags preserved:
- ignore_data
- is_waiting_body
- is_waiting_request_stream_start
The dual state tracking allows gradual migration. Future steps will
replace boolean flag checks with state machine checks incrementally.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add FetchError union to consolidate scattered error handling into a single
type with clear precedence rules. Currently errors are spread across
result.fail, abort_reason, and body errors. This union provides a
foundation for unified error management.
Added:
- FetchError union with 5 variants (none, http_error, abort_error, js_error, tls_error)
- set() method that frees old error before setting new (prevents leaks)
- toJS() method to convert error to JSValue for promise rejection
- isAbort() helper for special abort handling
- Single deinit() cleanup for all variants
Error precedence documented:
1. abort_error (highest - user initiated)
2. js_error (JavaScript callback errors)
3. tls_error (TLS validation failures)
4. http_error (lowest - network/protocol errors)
This is a non-breaking addition. Future phases will migrate existing
error handling to use this unified storage.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive documentation for request body streaming cleanup with
explicit ownership transfer semantics. The previously obscure "initExactRefs(2)"
pattern is now fully documented with clear ref counting explanations.
Changes:
- Enhanced startRequestStream() with detailed ref counting documentation
- Renamed clearSink() to clearRequestStreaming() with full ref docs
- Added clearSink() compatibility alias for backward compatibility
- Documented which refs are held by sink, stream, and buffer
- Explained ownership transfer at each step
The "initExactRefs(2)" pattern is now explicit:
- Ref 1: FetchTasklet.sink field (our ownership)
- Ref 2: Consumed when stream pipes to sink
All cleanup paths are documented with inline comments explaining
which refs are being dropped and which remain held by other owners.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add 4 new functions to separate body streaming logic into clear state-based
handlers, replacing the complex conditionals in onBodyReceived. This makes
the code more maintainable and prepares for future SharedData migration.
Added functions:
- processBodyDataInitial() - Decides whether to buffer or stream initially
- streamBodyToJS() - Streams body data to ReadableStream (dual-path support)
- bufferBodyData() - Buffers body in memory and creates InternalBlob when done
- bufferBodyDataDirect() - Directly appends data to buffer with OOM handling
These functions are currently unused (will be integrated in next step) but
compile successfully. They handle all 3 existing code paths: direct stream,
Response body stream, and buffering.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Replace manual hostname buffer management with bun.ptr.Owned wrapper for
automatic RAII cleanup and explicit ownership tracking. The hostname buffer
is optionally allocated for TLS certificate validation with custom
checkServerIdentity.
Changes:
- Changed hostname field from ?[]u8 to ?bun.ptr.Owned([]u8)
- Wrap allocation with bun.ptr.Owned([]u8).fromRaw()
- Replace manual free() calls with automatic hostname.deinit()
- Unwrap with .get() when passing to HTTP client
- Add comprehensive documentation explaining ownership model
The wrapper ensures automatic cleanup via RAII pattern, eliminating manual
memory management and reducing risk of leaks in future code paths.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add AbortHandling wrapper struct to centralize abort signal lifecycle
management and eliminate scattered ref/unref operations that can cause
leaks or use-after-free bugs.
Added:
- AbortHandling struct with private state tracking fields
- #signal, #has_pending_activity_ref, #has_listener fields
- attachSignal() method for atomic setup (ref, listener, pending activity)
- detach() method for proper cleanup in correct order
- Single deinit() method calling detach()
- onAbortCallback() static method for abort event handling
The wrapper ensures all ref/unref operations are paired correctly in
single code paths. Private fields prevent external code from bypassing
lifecycle management, making ownership explicit and preventing common
memory safety bugs.
Note: onAbortCallback() retains reason parameter as required by
AbortSignal.listen() API constraint.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add comprehensive documentation for url_proxy_buffer ownership pattern
instead of adding bun.ptr.Owned wrapper. The current pattern is already
clear and explicit, so documentation makes it even more obvious without
adding abstraction overhead.
Added documentation:
- Complete ownership model with 5-step lifecycle
- Buffer layout explanation (URL + optional proxy concatenated)
- Cross-references to creation site (fetch.zig) and cleanup site
- Alternative considered section explaining bun.ptr.Owned approach
- Rationale for choosing explicit pattern over wrapper
- Single cleanup path documentation in clearData()
The ownership transfer pattern (setting to "" after transfer) already
prevents double-free. Documentation makes this implicit pattern explicit
for future maintainers.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add HTTPRequestBodyV2 union to make request body ownership explicit and
eliminate fragile ref counting patterns. Each variant tracks its own
ownership state with private fields.
Added:
- HTTPRequestBodyV2 union with 4 variants (Empty, AnyBlob, Sendfile, ReadableStream)
- AnyBlob variant with nested #store_ref struct tracking blob store refs
- Sendfile variant with #owns_fd field to track FD ownership
- ReadableStream variant with #transferred_to_sink field documenting initExactRefs(2)
- transferToSink() method for explicit ownership transfer to sink
- Single deinit() method dispatching to variant-specific cleanup
- Helper methods store() and refStore() for blob ref counting
The union makes ownership clear at creation time and provides variant-specific
cleanup logic. The ReadableStream variant explicitly documents the ref counting
pattern to prevent double-retain bugs.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add ResponseMetadataHolder wrapper struct to make metadata ownership
transfer explicit and ensure metadata is only transferred once to the
Response object. This prevents use-after-free and double-free bugs.
Added:
- ResponseMetadataHolder struct with private metadata and certificate fields
- takeMetadata() method for one-time ownership transfer
- takeCertificate() method for one-time ownership transfer
- setMetadata() method that frees old metadata before storing new
- setCertificate() method that frees old certificate before storing new
- Single deinit() method with null-safe cleanup
The take semantics ensure metadata can only be consumed once, with
subsequent calls returning null. This makes the ownership contract
explicit and prevents common memory safety bugs.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add RequestHeaders wrapper struct to make header ownership explicit and
eliminate scattered conditional cleanup logic. This is a non-breaking
addition that encapsulates the "do I need to free this?" decision.
Added:
- RequestHeaders struct with private owned field
- initEmpty() factory for non-owned headers (no cleanup needed)
- initFromFetchHeaders() factory for owned headers (requires cleanup)
- Single deinit() method that checks ownership flag
- borrow() method to access underlying Headers
The wrapper makes ownership clear at creation time and provides a single
cleanup path, eliminating error-prone conditional logic.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Improve thread safety and reduce lock contention in HTTP thread callbacks by
making the handoff from HTTP thread to main thread explicit and minimizing
work done under lock.
HTTP Thread Improvements:
- Add fast-path abort check before acquiring lock (atomic read only)
- Move duplicate scheduling check before lock (reduces contention)
- Keep critical section brief (just data copying)
- Handle OOM gracefully under lock
- Add ref() before enqueueTaskConcurrent for proper lifetime management
Main Thread Improvements:
- Dramatically reduce lock holding time (from ~150 lines to ~30 lines)
- Copy state out under lock, then release before JS work
- Perform all JS interactions without lock (certificate validation, promise resolution)
- Add unconditional deref() at start to balance HTTP thread ref()
- Re-acquire lock briefly only when needed
Reference Counting:
- HTTP thread: ref() before each enqueue to main thread
- Main thread: unconditional defer deref() at callback start
- Prevents use-after-free and reference leaks
- Matches existing onWriteRequestDataDrain/resumeRequestDataStream pattern
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Fix potential memory leak and use-after-free in derefFromThread when VM is
shutting down. The function now checks VM shutdown status before enqueueing
cleanup tasks, intentionally leaking memory (detected by ASAN) rather than
risking use-after-free crashes.
Changes:
- Add VM shutdown pre-check before enqueueTaskConcurrent
- Add debug logging for intentional leaks during shutdown
- Add deinitFromMainThread helper with main thread assertion
- Early return on shutdown to prevent unsafe cleanup attempts
This is safer than attempting cleanup during VM shutdown and makes the
memory safety trade-off explicit: leak detection over undefined behavior.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Fix critical race condition in Bun__FetchResponse_finalize where the function
accessed shared state without acquiring the mutex, racing with the HTTP
thread's callback() which does lock the mutex.
Changes:
- Add mutex acquisition at function entry with RAII defer unlock
- Inline ignoreRemainingResponseBody logic under lock protection
- Set abort flag atomically with .release ordering
- Clear buffers safely under lock (prevents concurrent modification)
- Invert promise check logic for clearer control flow
The dual ownership pattern (response_weak + native_response) is intentional
and remains unchanged for finalization tracking.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add thread safety architecture with clear separation between main-thread-only
data and shared data that requires mutex protection. This is a non-breaking
change that adds new types without modifying existing FetchTasklet logic.
Added:
- MainThreadData struct with 12 fields for main thread only data
- SharedData struct with 14 fields for cross-thread shared data
- LockedSharedData RAII wrapper for safe mutex handling
- Comprehensive documentation of ownership and thread safety patterns
All structs are at module level for architectural clarity.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Add FetchLifecycle and RequestStreamState enums to replace boolean flag
soup with explicit multi-dimensional state tracking. This is a non-breaking
change that adds new types without modifying existing logic.
Added:
- FetchLifecycle enum with 10 states and 4 helper methods
- RequestStreamState enum with 4 states
- transitionLifecycle() helper with debug assertions
- shouldIgnoreBodyData() computed property
- Comprehensive documentation and state transition examples
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
## Summary
Extract `FetchTasklet` struct from `src/bun.js/webcore/fetch.zig` into
its own file at `src/bun.js/webcore/fetch/FetchTasklet.zig` to improve
code organization and modularity.
## Changes
- Moved `FetchTasklet` struct definition (1336 lines) to new file
`src/bun.js/webcore/fetch/FetchTasklet.zig`
- Added all necessary imports to the new file
- Updated `fetch.zig` line 61 to import `FetchTasklet` from the new
location: `pub const FetchTasklet =
@import("./fetch/FetchTasklet.zig").FetchTasklet;`
- Verified compilation succeeds with `bun bd`
## Impact
- No functional changes - this is a pure refactoring
- Improves code organization by separating the large `FetchTasklet`
implementation
- Makes the codebase more maintainable and easier to navigate
- Reduces `fetch.zig` from 2768 lines to 1433 lines
## Test plan
- [x] Built successfully with `bun bd`
- [x] No changes to functionality - pure code organization refactor
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
### What does this PR do?
fixes#23901
### How did you verify your code works?
with a test
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
## Summary
Fixes a bug where `bun update --interactive` only updated `package.json`
but didn't actually install the updated packages. Users had to manually
run `bun install` afterwards.
## Root Cause
The bug was in `savePackageJson()` in
`src/cli/update_interactive_command.zig`:
1. The function wrote the updated `package.json` to disk
2. But it **didn't update the in-memory cache**
(`WorkspacePackageJSONCache`)
3. When `installWithManager()` ran, it called `getWithPath()` which
returned the **stale cached version**
4. So the installation proceeded with the old dependencies
## The Fix
Update the cache entry after writing to disk (line 116):
```zig
package_json.*.source.contents = new_package_json_source;
```
This matches the behavior in `updatePackageJSONAndInstall.zig` line 269.
## Test Plan
Added comprehensive regression tests in
`test/cli/update_interactive_install.test.ts`:
- ✅ Verifies that `package.json` is updated
- ✅ Verifies that `node_modules` is updated (this was failing before the
fix)
- ✅ Tests both normal update and `--latest` flag
- ✅ Compares installed version to confirm packages were actually
installed
Run tests with:
```bash
bun bd test test/cli/update_interactive_install.test.ts
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
## Summary
Adds a `subscriptions` getter to `ServerWebSocket` that returns an array
of all topics the WebSocket is currently subscribed to.
## Implementation
- Added `getTopicsCount()` and `iterateTopics()` helpers to uWS
WebSocket
- Implemented C++ function `uws_ws_get_topics_as_js_array` that:
- Uses `JSC::MarkedArgumentBuffer` to protect values from GC
- Constructs JSArray directly in C++ for efficiency
- Uses template pattern for SSL/TCP variants
- Properly handles iterator locks with explicit scopes
- Exposed as `subscriptions` getter property on ServerWebSocket
- Returns empty array when WebSocket is closed (not null)
## API
```typescript
const server = Bun.serve({
websocket: {
open(ws) {
ws.subscribe("chat");
ws.subscribe("notifications");
console.log(ws.subscriptions); // ["chat", "notifications"]
ws.unsubscribe("chat");
console.log(ws.subscriptions); // ["notifications"]
}
}
});
```
## Test Coverage
Added 5 comprehensive test cases covering:
- Basic subscription/unsubscription flow
- All subscriptions removed
- Behavior after WebSocket close
- Duplicate subscriptions (should only appear once)
- Multiple subscribe/unsubscribe cycles
All tests pass with 24 assertions.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
### What does this PR do?
Allows optional peers to resolve to package if possible.
Optional peers aren't auto-installed, but they should still be given a
chance to resolve. If they're always left unresolved it's possible for
multiple dependencies on the same package to result in different peer
resolutions when they should be the same. For example, this bug this
could cause monorepos using elysia to have corrupt node_modules because
there might be more than one copy of elysia in `node_modules/.bun` (or
more than the expected number of copies).
fixes#23725
most likely fixes#23895
fixes ENG-21411
### How did you verify your code works?
Added a test for optional peers and non-optional peers that would
previously trigger this bug.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* Improved resolution of optional peer dependencies during isolated
installations, with better propagation across package hierarchies.
* **Tests**
* Added comprehensive test suite covering optional peer dependency
scenarios in isolated workspaces.
* Added test fixtures for packages with peer and optional peer
dependencies.
* Enhanced lockfile migration test verification using snapshot-based
assertions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
### What does this PR do?
When `napi_create_external_buffer` receives empty input, the returned
buffer should be detached.
This fixes the remaining tests in `ref-napi` other than three that use a
few uv symbols
<img width="329" height="159" alt="Screenshot 2025-11-01 at 8 38 01 PM"
src="https://github.com/user-attachments/assets/2c75f937-79c5-467a-bde3-44e45e05d9a0"
/>
### How did you verify your code works?
Added tests for correct values from `napi_get_buffer_info`,
`napi_get_arraybuffer_info`, and `napi_is_detached_arraybuffer` when
given an empty buffer from `napi_create_external_buffer`
---------
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
## Summary
Adds comprehensive documentation explaining how Bun's event loop works,
including task draining, microtasks, process.nextTick, and I/O polling
integration.
## What does this document?
- **Task draining algorithm**: Shows the exact flow for processing each
task (run → release weak refs → drain microtasks → deferred tasks)
- **Process.nextTick ordering**: Explains batching behavior - all
nextTick callbacks in current batch run, then microtasks drain
- **Microtask integration**: How JavaScriptCore's microtask queue and
Bun's nextTick queue interact
- **I/O polling**: How uSockets epoll/kqueue events integrate with the
event loop
- **Timer ordering**: Why setImmediate runs before setTimeout
- **Enter/Exit mechanism**: How the counter prevents excessive microtask
draining
## Visual aids
Includes ASCII flowcharts showing:
- Main tick flow
- autoTick flow (with I/O polling)
- Per-task draining sequence
## Code references
All explanations include specific file paths and line numbers for
verification:
- `src/bun.js/event_loop/Task.zig`
- `src/bun.js/event_loop.zig`
- `src/bun.js/bindings/ZigGlobalObject.cpp`
- `src/js/builtins/ProcessObjectInternals.ts`
- `packages/bun-usockets/src/eventing/epoll_kqueue.c`
## Examples
Includes JavaScript examples demonstrating:
- nextTick vs Promise ordering
- Batching behavior when nextTick callbacks schedule more nextTicks
- setImmediate vs setTimeout ordering
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
### What does this PR do?
### How did you verify your code works?
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Bug Fixes**
* Improved HTTP connection handling during write failures to ensure more
reliable timeout behavior and connection state management.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
### What does this PR do?
If the input was empty `ArrayBuffer::createFromBytes` would create a
buffer that `JSUint8Array::create` would see as detached, so it would
throw an exception. This would likely cause crashes in `node-addon-api`
because finalize data is freed if `napi_create_external_buffer` fails,
and we already setup the finalizer.
Example of creating empty buffer:
a7f62a4caa/src/binding.cc (L687)fixes#6737fixes#10965fixes#12331fixes#12937fixes#13622
most likely fixes#14822
### How did you verify your code works?
Manually and added tests.
## Summary
Removes the `MemoryReportingAllocator` wrapper and simplifies
`fetch.zig` to use `bun.default_allocator` directly. The
`MemoryReportingAllocator` was wrapping `bun.default_allocator` to track
memory usage for reporting to the VM, but this added unnecessary
complexity and indirection without meaningful benefit.
## Changes
**Deleted:**
- `src/allocators/MemoryReportingAllocator.zig` (96 lines)
**Modified `src/bun.js/webcore/fetch.zig`:**
- Removed `memory_reporter: *bun.MemoryReportingAllocator` field from
`FetchTasklet` struct
- Removed `memory_reporter: *bun.MemoryReportingAllocator` field from
`FetchOptions` struct
- Replaced all `this.memory_reporter.allocator()` calls with
`bun.default_allocator`
- Removed all `this.memory_reporter.discard()` calls (no longer needed)
- Simplified `fetch()` function by removing memory reporter
allocation/wrapping/cleanup code
- Updated `deinit()` and `clearData()` to use `bun.default_allocator`
directly
**Cleanup:**
- Removed `MemoryReportingAllocator` export from `src/allocators.zig`
- Removed `MemoryReportingAllocator` export from `src/bun.zig`
- Removed `bun.MemoryReportingAllocator.isInstance()` check from
`src/safety/alloc.zig`
## Testing
- ✅ Builds successfully with `bun bd`
- All fetch operations now use `bun.default_allocator` directly
## Impact
- **Net -116 lines** of code
- Eliminates allocator wrapper overhead in fetch operations
- Simplifies memory management code
- No functional changes to fetch behavior
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
### What does this PR do?
calling `loadConfigPath` could allow loading bunfig more than once.
### How did you verify your code works?
manually
---------
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>