workers-sdk
workers-sdk copied to clipboard
Starting inspector failed: address in use with `wrangler dev --local`
When I run wrangler dev --local I get the following error:
Starting inspector on 0.0.0.0:9229 failed: address already in use
The port is not in use according to lsof -nP -iTCP -sTCP:LISTEN | grep 9229.
This only happens in local mode.
This didn't happen in wrangler 2.0.24, but it does in 2.1.4. I'm not sure which version it was introduced at.
Environment and versions
Fill out the following information about your environment.
- operating system: macOS Monterey 10.24
- output of
wrangler -V: wrangler 2.1.4 - output of
node -v: v18.0.0 - content of
wrangler.toml:
name = "replidraw"
main = "worker/index.ts"
compatibility_date = "2022-06-03"
[durable_objects]
bindings = [
{ name = "roomDO", class_name = "RoomDO" },
{ name = "authDO", class_name = "AuthDO" }
]
[[migrations]]
tag = "v1"
new_classes = ["Server"]
[[migrations]]
tag = "v2"
renamed_classes = [{from = "Server", to = "RoomDO" }]
new_classes = ["AuthDO"]
[triggers]
crons = [ "*/5 * * * *" ] # ever 5 mins for AuthDO connection revalidation
#[secrets]
#DATADOG_API_KEY
#REFLECT_AUTH_API_KEY
not sure when this change was made, but wrangler dev --local (and the reason i'm looking into this, pages dev) opens miniflare in a child process with child_process.fork. However, there seems to be a known issue where the node cli option --inspect does not work with child_process.fork.
https://github.com/nodejs/node/issues/9435
has there been any updates on this?
I know not useful, but this is affecting us as well (version 2.1.13 and running pages dev). This has made it so that it's near impossible to debug our functions. FWIW we're also using Remix to generate our functions.
With some simple chopping I found that wrangler 2.0.24 seems to be OK, and 2.0.25 is broken. Though I noted that 2.0.24 outputs two messages:
Debugger listening on ws://localhost:9229/a571cda8-bfab-4540-9832-7bda208f563c
Debugger listening on ws://localhost:9229/a571cda8-bfab-4540-9832-7bda208f563c
For help, see: https://nodejs.org/en/docs/inspector
[mf:inf] Worker reloaded! (8.70KiB)
[mf:inf] Listening on localhost:8787
The changelog shows lots of changes from 2.0.24 to 2.0.25: https://github.com/cloudflare/wrangler2/blob/0d2d6bf2f8d57ccf1d0c9e0043edbfb642b70a4b/packages/wrangler/CHANGELOG.md#2025
From a time perspective, 2.0.24 was released 1st August 2022, and 2.0.25 released 10th August 2022.
Not sure if it is relevant, but I'm running on a mac (Monterey 12.6).
Running wrangler 2.4.0 on linux this is the process tree I see:
637679 pts/0 S+ 0:00 | | | \_ sh -c cross-env NODE_ENV=development wrangler pages dev ./public
637680 pts/0 Sl+ 0:00 | | | \_ node /home/daniel/Repositories/jaitaiwan/blog/node_modules/.bin/cross-env NODE_ENV=development wrangler pages dev ./public
637695 pts/0 Sl+ 0:00 | | | \_ node /home/daniel/Repositories/jaitaiwan/blog/node_modules/.bin/wrangler pages dev ./public
637706 pts/0 Sl+ 0:03 | | | \_ /home/daniel/.nodenv/versions/16.13.0/bin/node --no-warnings --experimental-vm-modules /home/daniel/Repositories/jaitaiwan/blog/node_modules/wrangler/wrangler-dist/cli.js pages dev ./public
The terminal reports Starting inspector on 0.0.0.0:9229 failed: address already in use. So far as I can tell the issue happens with miniflare-dist/index.mjs being run with the --inspect flag as well?
As evidenced by another tree:
637658 pts/0 Sl+ 0:01 | | | \_ npm run dev:wrangler
637679 pts/0 S+ 0:00 | | | \_ sh -c cross-env NODE_ENV=development wrangler pages dev ./public
637680 pts/0 Sl+ 0:00 | | | \_ node /home/daniel/Repositories/jaitaiwan/blog/node_modules/.bin/cross-env NODE_ENV=development wrangler pages dev ./public
637695 pts/0 Sl+ 0:00 | | | \_ node /home/daniel/Repositories/jaitaiwan/blog/node_modules/.bin/wrangler pages dev ./public
637706 pts/0 Sl+ 0:05 | | | \_ /home/daniel/.nodenv/versions/16.13.0/bin/node --no-warnings --experimental-vm-modules /home/daniel/Repositories/jaitaiwan/blog/node_modules/wrangler/wrangler-dist/cli.js pages dev ./public
637731 pts/0 Sl+ 0:00 | | | \_ /home/daniel/Repositories/jaitaiwan/blog/node_modules/esbuild-linux-64/bin/esbuild --service=0.14.51 --ping
637764 pts/0 Sl+ 0:37 | | | \_ /home/daniel/Repositories/jaitaiwan/blog/node_modules/esbuild-linux-64/bin/esbuild --service=0.14.51 --ping
637806 pts/0 Sl+ 0:00 | | | \_ /home/daniel/.nodenv/versions/16.13.0/bin/node --experimental-vm-modules --no-warnings --inspect=0.0.0.0:9229 /home/daniel/Repositories/jaitaiwan/blog/node_modules/wrangler/miniflare-dist/index.mjs {"port":8788,"scriptPath":"/tmp/tmp-637706-pRsSRc6h2gns/7z2skjkvjq.js","https":false,"host":"0.0.0.0","modules":true,"modulesRules":[{"type":"Text","include":["**/*.txt","**/*.html"]},{"type":"Data","include":["**/*.bin"]},{"type":"CompiledWasm","include":["**/*.wasm"]}],"compatibilityDate":"2022-11-17","compatibilityFlags":[],"kvNamespaces":[],"queueBindings":[],"queueConsumers":[],"r2Buckets":[],"durableObjects":{},"externalDurableObjects":{},"d1Databases":[],"cachePersist":true,"durableObjectsPersist":true,"kvPersist":true,"r2Persist":true,"liveReload":false,"bindings":{},"wasmBindings":{},"textBlobBindings":{},"dataBlobBindings":{},"sourceMap":true,"logUnhandledRejections":true,"crons":[],"logLevel":"warn","logOptions":{"prefix":"pages"},"enablePagesAssetsServiceBinding":{"directory":"/home/daniel/Repositories/jaitaiwan/blog/public"}} {"directory":"/home/daniel/Repositories/jaitaiwan/blog/public"}
I did a comparison between the two release versions as mentioned above (2.0.24 vs 2.0.25) and I can't see anything that stands out about that except that the inpect-port field was added then. https://github.com/cloudflare/wrangler2/compare/70e0ddbd84a2e74df78af4c708c120af19a3e4bd..db592f09de62d385f440d8aa38e09d01f10fca11
I think this is a duplicate of #1701
Closing as a duplicate of #1701. There is a potential workaround mentioned in this comment.