I see two ways to solve the 'get unused port' race.
1) We delay the close time of the socket as long as possible (meaning close it right before we exec the program that will use it). The calls to get the ports are here:
but they are not used until start is called. Further, two calls are right next to each other. On most systems the ephemeral port selection is random and thus a collision is unlikely. However we may as well eliminate that chance
2) Never close the socket. Set an ENV to the FD of that socket before forking the server off, then in the presence of that env create a socket from that FD. This solution should entirely eliminate the problem.
I see two ways to solve the 'get unused port' race.
1) We delay the close time of the socket as long as possible (meaning close it right before we exec the program that will use it). The calls to get the ports are here:
https:/ /github. com/openstack/ glance/ blob/master/ glance/ tests/functiona l/__init_ _.py#L470.
but they are not used until start is called. Further, two calls are right next to each other. On most systems the ephemeral port selection is random and thus a collision is unlikely. However we may as well eliminate that chance
2) Never close the socket. Set an ENV to the FD of that socket before forking the server off, then in the presence of that env create a socket from that FD. This solution should entirely eliminate the problem.
Any thoughts?