Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 BUG: Only one instance of Wrangler can be started #4912

Closed
penalosa opened this issue Feb 3, 2024 · 4 comments
Closed

🐛 BUG: Only one instance of Wrangler can be started #4912

penalosa opened this issue Feb 3, 2024 · 4 comments
Assignees
Labels
bug Something that isn't working regression Break in existing functionality as a result of a recent change

Comments

@penalosa
Copy link
Contributor

penalosa commented Feb 3, 2024

Which Cloudflare product(s) does this pertain to?

Wrangler core

What version(s) of the tool(s) are you using?

main

What version of Node are you using?

18

What operating system and version are you using?

macOS

Describe the Bug

Observed behavior

Checkout & build Wrangler locally, and then run npx wrangler dev in workers-sdk/fixtures/service-bindings-app/a and then in workers-sdk/fixtures/service-bindings-app/b. The second command will fail with Address already in use (127.0.0.1:9229)

Expected behavior

Multiple instances of Wrangler to be startable without error.

This first started regressing in #4830, and hasn't yet been published in a Wrangler release.

Please provide a link to a minimal reproduction

N/A

Please provide any relevant error logs

N/A

@penalosa penalosa added bug Something that isn't working regression Break in existing functionality as a result of a recent change labels Feb 3, 2024
@github-project-automation github-project-automation bot moved this to Untriaged in workers-sdk Feb 3, 2024
@petebacondarwin
Copy link
Contributor

This is not reproducible in node 16. I think it is a reoccurence of the old node 18 switching to IPV6 by default problem.

@petebacondarwin
Copy link
Contributor

OK so looking into this I think the problem is this line where we use localhost for the host in the getPort() call:

const getInspectorPort = memoizeGetPort(DEFAULT_INSPECTOR_PORT, "localhost");

I believe that what is happening here is that localhost gets resolve to both 127.0.0.1 and ::1.
The first call to this (by Worker a) checks localhost:9229 and is told it is free (because 127.0.0.1:9229 is free. So it uses that port and starts listening on 127.0.0.1:9229.
The second call to this (by Worker b) checks localhost:9229 and is told it is free (because [::1]:9229 is free). So it uses that port and tries to start listening on 127.0.0.1:9229which of course fails because that is already in use by Worker a.

If you change the line above to use 127.0.0.1 as the host explicitly then the second call (Worker b) gets a completely new port and that seems to solve the problem.

I think this does not fail in node 16 because it does not have support for IPV6 so calling getPort() with localhost only ever checks 127.0.0.1.

cc @Lekensteyn

@petebacondarwin
Copy link
Contributor

petebacondarwin commented Feb 3, 2024

An alternative solution is to ask workerd to listen on localhost explicitly, rather than leaving it undefined, which means that workerd is able to pick the other IP address, here:

unsafeDirectHost: this.latestConfig.dev?.inspector?.hostname,

e.g.

unsafeDirectHost:
	this.latestConfig.dev?.inspector?.hostname ?? "localhost",

But I am worried that we then have two different servers listening on localhost:9229 and it is not clear how to distinguish between them. So I think the explicit use of IPv4 127.0.0.1 across all these internal servers is the best approach.

@admah admah moved this from Untriaged to Backlog in workers-sdk Feb 5, 2024
@petebacondarwin petebacondarwin moved this from Backlog to In Progress in workers-sdk Feb 6, 2024
@penalosa
Copy link
Contributor Author

penalosa commented Feb 7, 2024

Fixed in #4907

@penalosa penalosa closed this as completed Feb 7, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in workers-sdk Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that isn't working regression Break in existing functionality as a result of a recent change
Projects
None yet
Development

No branches or pull requests

2 participants