fix(miniflare): use 127.0.0.1 for internal loopback to prevent IPv6/IPv4 mismatch CPU spins#12913
Conversation
🦋 Changeset detectedLatest commit: 824da61 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
|
Thanks @devin-ai-integration! I've pushed a commit fixing the missed |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
|
Thanks for working on this. My main concern with this approach is that it changes the default public dev host from My understanding is that the bug comes from the internal Miniflare/workerd communication using an ambiguous host. I wonder if it would be better to make that internal path use a concrete address while leaving the user-facing host unchanged. What do you think? |
9b61dc5 to
4324b73
Compare
|
Thanks for the feedback @edmundhung! You're absolutely right - the original approach was too broad. I've updated the PR to take a more surgical approach: What changed:
Why this works: Files changed:
This approach:
Let me know if you'd like any adjustments! |
dev IP to 127.0.0.1 instead of localhost to prevent CPU spins|
@edmundhung I've added a changeset file as requested by the bot. The PR now includes:
Ready for review when you have a moment. Thanks! |
|
@Sigmabrogz This is looking good, thanks! I just pushed a small follow-up to your branch to handle the module fallback service as well. Once I get another pair of eyes on this from my team, we should be in a good place to merge. |
|
@Sigmabrogz Can you please update the description following the PR Template? We have a CI check about that and fails because of that. |
|
Updated the PR description to match the repo template so CI passes! |
e1fcbf6 to
adf19be
Compare
|
Codeowners approval required for this PR:
Show detailed file reviewers |
… configured This fixes the IPv6/IPv4 mismatch issue where Node.js binds to [::1] but workerd resolves localhost to 127.0.0.1, causing a tight CPU spin loop. The fix only affects the internal loopback communication between Node.js and workerd, keeping the user-facing URL as localhost. Fixes cloudflare#12910 Made-with: Cursor
Made-with: Cursor
adf19be to
824da61
Compare
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
Describe your change...
Summary
This fixes the internal loopback communication between Node.js and workerd to prevent IPv6/IPv4 mismatch issues when `localhost` is configured.
Problem
When running `wrangler dev`, if the system has IPv6 disabled but `localhost` still maps to both IPv4 and IPv6 in `/etc/hosts` (the default on most distros), Node.js may bind the internal loopback port to `[::1]` (IPv6).
However, `workerd` resolves `localhost` to `127.0.0.1` (IPv4) first when constructing the `--external-addr=loopback=` parameter. This results in a connection refused error, and `workerd` attempts to reconnect immediately without backoff, causing 100% CPU usage.
Solution
Instead of changing the user-facing default IP (which could affect setups depending on `localhost`), this PR takes a more surgical approach:
This ensures both Node.js and workerd agree on the IPv4 loopback address for internal communication, while preserving the existing user-facing behavior.
Changes
A picture of a cute animal (not mandatory, but encouraged)
