Port availability might be tricky if some port is already in use on the
'all' interface '0.0.0.0'.
The proposed solution is to let the OS allocate the port for us using 0
as port specifier :
- first create a server instance to allocate a port number
- save port number
- close the server
- return the port number to the caller
This should be safe granted the OS doesn't reuse the port numbers on
consecutive port allocations.
see :
- about Node.js Net module : https://nodejs.org/docs/latest-v12.x/api/net.html#net_server_listen_port_host_backlog_callback
- about safety around reusing port number : https://unix.stackexchange.com/a/132524
Signed-off-by: Alexis Deruelle <alexis.deruelle@gmail.com>
Problem raised on macOS where port 49152 was used by rapportd process
listening on 0.0.0.0 address and as a consequence the application proxy
server wasn't correctly setup that in turn disrupted the webview display
that wasn't served through http://<uid>.localhost:49152/ (#255)
Indeed the checkPort() function was checking port availability using the
127.0.0.1 address that doesn't error.
The minimal fix here is to test port availability using 0.0.0.0 address.
Signed-off-by: Alexis Deruelle <alexis.deruelle@gmail.com>