cloudflare / workers-sdk

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

🐛 BUG: ConnectionClosed: The socket connection was closed unexpectedly. #6176

Open mattp0123 opened 3 days ago

mattp0123 commented 3 days ago

Which Cloudflare product(s) does this pertain to?

Workers Runtime, Wrangler core

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

3.62.0 [Wrangler]

What version of Node are you using?

20.15.0

What operating system and version are you using?

Mac Sonoma 14.5

Describe the Bug

Observed behavior

I'm not sure if it's bun related. When I using bun to run a .ts script to send a request (fetch) to my local dev worker, it throws this error:

ConnectionClosed: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()
 path: "http://localhost:8787/"

Then I make any change to worker code and hit save, the wrangler server shuts down and shows the error. (I write it down in below section)

Expected behavior

No errors.

Steps to reproduce

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

/Users/matt/.bun/install/global/node_modules/wrangler/wrangler-dist/cli.js:29747
            throw a;
            ^

TypeError: fetch failed
    at Object.fetch (/Users/matt/.bun/install/global/node_modules/undici/index.js:112:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async fetch3 (/Users/matt/.bun/install/global/node_modules/miniflare/dist/src/index.js:4286:20)
    at async Miniflare2.dispatchFetch (/Users/matt/.bun/install/global/node_modules/miniflare/dist/src/index.js:9315:22)
    at async Mutex.runWith (/Users/matt/.bun/install/global/node_modules/miniflare/dist/src/index.js:3521:16)
    at async ProxyController.sendMessageToProxyWorker (/Users/matt/.bun/install/global/node_modules/wrangler/wrangler-dist/cli.js:208734:7) {
  cause: AggregateError [ECONNREFUSED]: 
      at internalConnectMultiple (node:net:1117:18)
      at afterConnectMultiple (node:net:1684:7)
      at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    code: 'ECONNREFUSED',
    [errors]: [
      Error: connect ECONNREFUSED ::1:8787
          at createConnectionError (node:net:1647:14)
          at afterConnectMultiple (node:net:1677:16)
          at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
        errno: -61,
        code: 'ECONNREFUSED',
        syscall: 'connect',
        address: '::1',
        port: 8787
      },
      Error: connect ECONNREFUSED 127.0.0.1:8787
          at createConnectionError (node:net:1647:14)
          at afterConnectMultiple (node:net:1677:16)
          at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
        errno: -61,
        code: 'ECONNREFUSED',
        syscall: 'connect',
        address: '127.0.0.1',
        port: 8787
      }
    ]
  }
}