http-party / node-portfinder

A simple tool to find an open port or domain socket on the current machine
https://github.com/http-party/node-portfinder
Other
887 stars 95 forks source link

Feature: allow usage of a lock to avoid race conditions #150

Closed AndreaMontalbani closed 2 months ago

AndreaMontalbani commented 2 months ago

The following jest test stub does not pass, randomly, which means concurrent calls can return the same port:

test("Tests portfinder",async ()=>{ const resPorts= await Promise.all([1,2,3,4,5].map(_=>portfinder.getPortPromise({ port: 20001,
stopPort: 20007 }))) expect(resPorts.length).toEqual((new Set(resPorts)).size); })

I am not sure if it is a wanted feature, seen the simple nature of the package but I needed this in a project.

AndreaMontalbani commented 2 months ago

Doesn't make much sense without an underlying process occupying the ports