workers-sdk icon indicating copy to clipboard operation
workers-sdk copied to clipboard

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

Open mattp0123 opened this issue 1 year ago • 0 comments

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

  • wrangler.toml:
name = "my-worker"
compatibility_date = "2023-12-01"
workers_dev = false
main = "index.ts"
  • Start the local dev worker by running bunx wrangler dev, the worker code:
export default {
  async fetch() {
    return new Response("OK");
  },
}
  • Run the script with bun run my-script.ts, the script:
const res = await fetch('http://localhost:8787')

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
      }
    ]
  }
}

mattp0123 avatar Jul 02 '24 02:07 mattp0123