2

On linux (Ubuntu 19.x)

I get an "address already in use" even if a port is free in some situations (e.g. TCP listener that wasn't closed properly).

This happens if I e.g. kill a process with fuser.

The address is released after an arbitrary amount of time but this wait is seriously hampering me.

Is there any way to just "force free" an address ?

George
  • 3,521
  • 4
  • 30
  • 75
  • 2
    You can enable `SO_REUSEADDR` with `setsockopt(2)` to allow your program to bind to the port immediately. See [this example](https://stackoverflow.com/questions/24194961/how-do-i-use-setsockoptso-reuseaddr) – that other guy Jun 30 '20 at 22:47

1 Answers1

-1

Try to kill the orphaned processes if your program spawned any while it's running. Or find out which process is still holding the internet port, and kill it.

sudo lsof -i :port
Chuan
  • 3,103
  • 1
  • 19
  • 23