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

Aperta
#16,964 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
backend, cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
4.7k
Fork
1.7k
Merge medio
1g 22h
PR unite (30g)
282

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/workers-sdk

Tutte le issue di cloudflare/workers-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.