Hacker News new | ask | show | jobs
by Uptrenda 2 days ago
I get the problem well. I have built a networking runtime and a Python networking library that extensively used servers as part of testing. If you bind to a specific port and reuse it, you can end up with false failures due to:

- old / zombie server processes

- sockets that weren't properly cleaned up

- TIME_WAITs

my solution wasn't anything as clever as OPs though. Basically, I ended up conceiving of 127/8 as a rotating ring. Where you can pass offsets and easily end up on an unused bind tup every time. 127/8 gives you a huge number of IPs to play with. You just make address handling part of your test launcher and it sets a new IP each time.

The issue is it doesn't really work for IPv6 (v6 localhost is only one address!) Though global-scope v6 interface blocks and manually assigned link-local scope, you could accomplish much the same thing.