servor icon indicating copy to clipboard operation
servor copied to clipboard

Starting two instances of Servor without port cause them having the same port

Open nestarz opened this issue 4 years ago • 2 comments

Using the API, I start two instances of Servor without waiting the first promise to finish, without port specified, the net library cause them to have the same port.

If I just do this it works:

const usePort = (port = 0) =>
  new Promise((ok, x) => {
    setTimeout(() => {
      const s = net.createServer();
      s.on('error', x);
      s.listen(port, () => (a = s.address()) && s.close(() => ok(a.port)));
    })
  });

They have two differents ports, (51159 and 51160 for example).

nestarz avatar May 24 '20 23:05 nestarz

Hey 👋 thanks for the report.. just so that I am clear whats going on, you do something like this:

import servor from 'servor';

servor({ ... })
servor({ ... })

And this results in both servers running on the same port?

lukejacksonn avatar May 26 '20 11:05 lukejacksonn

Exactly !

nestarz avatar May 26 '20 13:05 nestarz