fix: randomize the first port tried by portfinder

This commit is contained in:
fryorcraken.eth 2023-01-20 16:43:22 +11:00
parent 380ba6987a
commit 171fd1e6df
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 5 additions and 1 deletions

View File

@ -147,8 +147,12 @@ export class Nwaku {
const mergedArgs = defaultArgs();
// nwaku takes some time to bind port so to decrease chances of conflict
// we also randomize the first port that portfinder will try
const startPort = Math.floor(Math.random() * (65535 - 1025) + 1025);
const ports: number[] = await new Promise((resolve, reject) => {
portfinder.getPorts(3, {}, (err, ports) => {
portfinder.getPorts(3, { port: startPort }, (err, ports) => {
if (err) reject(err);
resolve(ports);
});