Two `wrangler dev` processes started together pick the same inspector port

Open
#16,964 2 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
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
node.js, typescript
Domain
backend, cli

Research direction

Start with packages/wrangler/src/api/startDevWorker/ConfigController.ts, especially resolveInspectorConfig, and trace how the inspector port is selected and passed to workerd. Reproduce the race using the linked repro, which starts two wrangler dev processes together with separate --port values. Done means concurrent starts avoid the inspector port collision or report the inspector address and --inspector-port accurately.

Written by the indexing model from the issue text.

Description

bug package:wrangler start-dev-worker
What versions & operating system are you using?

wrangler 4.163.0 (miniflare 5.20261116.0-beta, workerd 1.20261116.1), Node 24.21.0, Linux x64.

Please provide a link to a minimal reproduction

https://github.com/onmax/repros/tree/repro/wrangler-inspector-port-race/wrangler-inspector-port-race

Describe the Bug

When two wrangler dev processes start at the same moment, each with its own --port, both pick inspector port 9229 and one of them fails:

✘ [ERROR] Address already in use (socket "direct:1:default"). Please check that you are not already running a server on this address or specify a different port with --port.

This happens in scripts that serve two builds side by side, like a before/after benchmark. The repro starts two Workers together, five times in a row. Every run leaves one process that never answers (6/6 on my machine). Passing a distinct --inspector-port to each (CONTROL=1 pnpm verify) fixes it, 0/4. Started a few seconds apart, the second process moves to 9230 as expected.

The cause looks like a check-then-bind race. resolveInspectorConfig asks get-port for a free port from 9229 up. get-port binds the port, closes it, and returns the number. workerd binds it later, so both processes get 9229 in that window.

The error message makes it harder to find. direct:1:default is the inspector proxy's socket, but nothing says so, and the hint suggests --port, which is already different for each process. Naming the inspector address and --inspector-port in the message would point people to the fix.

Please provide any relevant error logs

See above. With CONTROL=1 both processes start in every run.

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.