cloudflare / cloudflare/workers-sdk

🐛 BUG: Wrangler throwing an error fails to clear port binding on exit

Open
#3,696 5 comments 1 reaction 4 assignees Claimed by @stritt View on GitHub
package:wrangler product:pages
Dominant language
TypeScript
Stars
4.5k
Forks
1.5k
Avg merge
3d 8h
Merged PRs (30d)
187

Description

### Which Cloudflare product(s) does this pertain to?

Wrangler core

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

3.4.0 [Wrangler]

### What version of Node are you using?

18.16.0

### What operating system are you using?

Linux archlinux 6.4.7-arch1-1

### Describe the Bug

If `wrangler pages dev` errors or otherwise stops unexpectedly it will hold it's bind to `:8788` making using it as intended with Next on Pages in Watch Mode impossible. The steps to reproduce are similar to [the next for pages docs](https://github.com/cloudflare/next-on-pages/tree/main/packages/next-on-pages#local-development-in-watch-mode):

Steps to Reproduce:
1. `npx @cloudflare/next-on-pages --watch`
2. Then, in another terminal run: `npx wrangler pages dev .vercel/output/static --compatibility-flag=nodejs_compat`
3. Trigger next-on-pages to refresh by modifying any file in the directory.
4. Notice `wrangler pages dev` has stopped and restart it with the same command, `npx wrangler pages dev .vercel/output/static --compatibility-flag=nodejs_compat`

Upon attempting to restart wrangler, you'll notice the following error:
```
*** Fatal uncaught kj::Exception: kj/async-io-unix.c++:945: failed: ::bind(sockfd, &addr.generic, addrlen): Address already in use; toString() = 0.0.0.0:8788
```

The only way to continue development locally is to find the PID of the hanging process with `lsof -i :8788`, kill it, then rerun wrangler pages dev. This issue makes it extremely difficult to use other Cloudflare offerings in Next on Pages projects locally, as R2 for example requires a worker to access it.

### Please provide a link to a minimal reproduction

_No response_

### Please provide any relevant error logs

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.