On 03.02.20 08:59, Lukáš Doktor wrote: > Using a range of ports from 32768 to 65538 is dangerous as some > application might already be listening there and interfere with the > testing. There is no way to reserve ports, but let's decrease the chance > of interactions by only using ports that were free at the time of > importing this module. > > Without this patch CI occasionally fails with used ports. Additionally I > tried listening on the first port to be tried via "nc -l localhost > $port" and no matter how many other ports were available it always > hanged for infinity.
I’m afraid I don’t quite understand. The new functions check whether the ports are available for use by creating a server on them (i.e., binding a socket there). The current code just lets qemu create a server there, and see if that works or not. So the only difference I can see is that instead of trying out random ports during the test and see whether they’re free to use we do this check only once when the test is started. And the only problem I can imagine from your description is that there is some other tool on the system that tries to set up a server but cannot because we already have an NBD server there (by accident). But I don’t see how checking for free ports once at startup solves that problem reliably. If what I guessed above is right, the only reliable solution I can imagine would be to allow users to specify the port range through environment variables, and then you’d have to specify a range that you know is free for use. Max