Description
The use of portfinder
to find an open port allows for a race condition when running multiple parallel instances of wtr.
The way portfinder
(and most other open port finding libraries) works is that it attempts to open a given port by starting a server, and if that succeeds it closes the server and returns the port number to the caller. In the time between closing the server and the caller starting it's own server another process can then claim the port. This happens quite easily with port 8000
if two wtr
s calls happen very quickly (as might happen with a parallel script runner like wireit
:) ).
The best solution we found when building Web Component Tester and polyserve was to move the open port finding in-house by actually trying to start our server and retrying if we failed because of an EADDRINUSE. This way once we found an open port we didn't have to release it and try to claim it again right away.