httptoolkit / httptoolkit-server

The backend of HTTP Toolkit
https://httptoolkit.com
GNU Affero General Public License v3.0
459 stars 101 forks source link

Address in use #137

Closed pcartwright81 closed 1 month ago

pcartwright81 commented 1 month ago

Had this error, below is what I found.

npm start

Config checked in 6 ms Certificates setup in 7 ms Error: listen EADDRINUSE: address already in use 127.0.0.1:45456 at Server.setupListenHandle [as _listen2] (node:net:1904:16) at listenInCluster (node:net:1961:12) at doListen (node:net:2135:7) at processTicksAndRejections (node:internal/process/task_queues:83:21) { code: 'EADDRINUSE', errno: -4091, syscall: 'listen', address: '127.0.0.1', port: 45456 } Error: listen EADDRINUSE: address already in use 127.0.0.1:45456 Code: EADDRINUSE Failed running './bin/run start'

Tried base server and it didn't work http-server -p 45456

Looked to ensure the port was not excluded. netsh int ip show excludedportrange protocol=tcp

Protocol tcp Port Exclusion Ranges

`Start Port End Port


  1462        1462
  5357        5357
 50000       50059     *
 51843       51942
 51943       52042
 52043       52142
 52143       52242

Read something that said to check docker also. Closed docker. http-server -p 45456 Success!

Open docker fail :(

Ok, so it's docker. Nothing is running, what could it be...
docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

Looked at the running wsl wsl --list --verbose NAME STATE VERSION

Connect to distro wsl --distribution docker-desktop

netstat -l | grep 45456 Blank! So it's not inside the container.

docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7ffdf6a5a9af vsc-core-19e32c148eda9be582235c93e2081af0d9e991c18c4d9ad3a1c2b54b8a8c79b6 "/bin/sh -c 'echo Co…" 15 hours ago Exited (0) 14 hours ago gallant_albattani ebe222bdc21f vsc-0.388.0-bf841eff84a044a4ed6a63a90de4c1777e69e6d8da1bc421e866cd47534f605f "/bin/sh -c 'echo Co…" 16 hours ago Exited (0) 16 hours ago adoring_khayyam

docker port shows nothing

Little lost on where to go from here

Update: close docker, start http toolkit, open http toolkit, open docker: Success!

Theory is docker will not take the port because it's in use and will not be a problem until I restart docker desktop. Will update when I am able to close it.

pimterry commented 1 month ago

That error is pretty clear, but I'm actually not aware of any other programs that use this port, so that is surprising. It's also very surprising for Docker to use ports like this without any containers actually running - that would be very very unusual ime.

The most common case where this error normally appears is because internal components of HTTP Toolkit are still running somewhere (these will appear in your process listing as either HTTP Toolkit, or Node.exe) and those are still using the port. That can happen during unusual crashes or similar. Does it sound like that might be what's happening here?

To investigate this further, I would normally suggest using tools like Netstat or similar. You'll generally want to use these from the host not from inside the Docker container. I don't know how WSL 2 works exactly here, but in most cases you have a separate network namespaces inside and outside containerization environments like this, with the containerization tool (such as Docker) mapping from one to the other. If you're running HTTP Toolkit in windows normally (i.e. you're not doing something very unusual to launch HTTP Toolkit inside Docker/WSL itself) then only the ports used in the host Windows environment should matter. If ports are used by Docker etc, I would expect those to be explicitly listed in netstat from the host. But again, I'm not that familiar with WSL so it's possible they do something very weird here.

Sorry I can't be more helpful! I haven't seen anything like this before myself and there's plenty of other windows users who aren't hitting this, so it's definitely something unusual about your setup, but I'm afraid I have no idea really what it could be.

pcartwright81 commented 1 month ago

Haven't ran into this issue again although that day I thought it persisted after a reboot. Will add more info if I do run into it again.