versatica / pick-port

Get a free TCP or UDP port for the given IP address

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getPort() returned Promise never fullfils if range is given

ibc opened this issue · comments

const pickPort = require('pick-port');

async function run()
{
	let port;

	port = await pickPort({ type: 'tcp', range: { min: 5000, max: 5001 }, reserveTimeout: 100 });
	console.info('picked TCP port: %d', port);

	port = await pickPort({ type: 'tcp', range: { min: 5000, max: 5001 }, reserveTimeout: 100 });
	console.info('picked TCP port: %d', port);

	port = await pickPort({ type: 'tcp', range: { min: 5000, max: 5001 }, reserveTimeout: 100 });
	console.info('picked TCP port: %d', port);

	port = await pickPort({ type: 'tcp', range: { min: 5000, max: 5001 }, reserveTimeout: 100 });
	console.info('picked TCP port: %d', port);
}

run();

Output:

picked TCP port: 5001
picked TCP port: 5000

(nothing else)

If I add a .catch((error) => ... in any pickPort() call then I get the proper "All ports in the given range are in use" error. However, it should also throw an error in the code above (instead, the code is suspended).