cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.6k stars 674 forks source link

🐛 BUG: Worker Registry fails to start(concurrent dev sessions) #6037

Closed helloimalastair closed 3 months ago

helloimalastair commented 3 months ago

Which Cloudflare product(s) does this pertain to?

Wrangler core

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

3.60.3

What version of Node are you using?

22.2.0

What operating system and version are you using?

MacOS Sonoma 14.5

Describe the Bug

Observed behavior

When starting multiple wrangler dev processes in quick succession(via a tool like turbo or similar), the sessions can end up fighting over which of them gets to start the Registry. Others fail with the error

 ✘ [ERROR] failed to start worker registry Error: listen EADDRINUSE: address already in use 127.0.0.1:6284

Expected behavior

One of the Dev Sessions should complete, and any others should wait for it to become available before throwing an error.

Steps to reproduce

  1. Create multiple Workers(doesn't matter their content). I did it with 5, but it should work with less/more too.
  2. Start wrangler dev on them all simultaneously.

Credit to @poacher2k for discovering/reporting this bug on the CF Discord.

petebacondarwin commented 3 months ago

The plan is to move to a file based registry in the shortish term. (There may be more significant approach to multi-worker development in the longer term). See https://github.com/cloudflare/workers-sdk/pull/5214 I'll see if we can prioritise landing this before the end of the month.

helloimalastair commented 3 months ago

Thank you, y'all!

zygimantas commented 2 months ago

Just in case someone will browse this issue, I was still getting same error with wrangler 3.65.1 with and without --x-registry flag.

My workaround is:

  1. Run worker1 wrangler dev --port=4201 worker1.ts
  2. Run worker2 wait-on tcp:4201 && wrangler dev --port=4202 worker2.ts