Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requested port is not assigned after 5.0.0 update, even though its available #43

Open
mikemykhaylov opened this issue Jan 2, 2020 · 3 comments

Comments

@mikemykhaylov
Copy link

Hello,

I have an issue. The code is:

./index.js

const getPort = require('get-port');
const {spawn} = require('child_process');
const processExists = require('process-exists');
const delay = require('delay')
const fkill = require('fkill');

async function test() {
  const port = await getPort();
  console.log(port);
  const {pid} = spawn('node', ['fixture.js', port]);
  console.log(`Process exists with PID: ${pid}: ${await processExists(pid)}`);
  await fkill(pid);
  await delay(100);
  console.log(`Process exists with PID: ${pid}: ${await processExists(pid)}`);
	if(!await processExists(pid)) {
    const samePort = await getPort({port});
    console.log(samePort);
  } else {
    console.log('Process not killed');
  }
}

test();

./fixture.js

'use strict';
const http = require('http');

const server = http.createServer((request, response) => {
	response.end();
});

server.listen(process.argv.slice(2)[0]);

With version 4.2.0 the output is as expected

60328
Process exists with PID: 15767: true
Process exists with PID: 15767: false
60328

With ^5.0.0, however, the second time I'm requesting the port, it comes out 1 more than before:

60343
Process exists with PID: 15945: true
Process exists with PID: 15945: false
60344

Has anyone here encountered this issue or knows any way to solve it?

@sindresorhus
Copy link
Owner

// @davidmarkclements

hacdias referenced this issue in ipfs/ipfs-desktop Apr 18, 2020
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
jan-molak added a commit to serenity-js/serenity-js that referenced this issue Jul 4, 2020
… on a random port after restart

Replaced get-port with portfinder to avoid issue sindresorhus/get-port#43
@mikemykhaylov
Copy link
Author

The package seems to be abandoned, closing the issue. Use portfinder for similar functionality

@sindresorhus
Copy link
Owner

Not abandoned, just lack of time on my part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants