Is there a better/simpler/easier way to synchronize access to a static variable? This seems overly complicated for a function that just produces incremented integers.
Using the offset of 9090 at the end is a great idea, thanks!
That way we can remove the initialization condition and always operate on a fixed offset of 9090. This is still not super intuitive because the initial value of our counter is at the very end which makes this function hard to read.
Using port 0: since these are all integration tests we need to get the actual port number that the kernel assigned - so I would have to implement a helper function that reads out the port number of my dummy server and of my reverse proxy. Does not seem simpler to me. That is also not how the proxy is used by users: port numbers are pre-determined and passed as configuration, I think the integration test should operate the same way.
that grabs a free port, then immediately drops the sockets and starts a new server. There is definitely a race condition here, but I have yet to ever see it get hit...