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

Port is already in use when I quit with CTRL+C and restart manually #1164

Closed
VasilisKosmas opened this issue Dec 14, 2017 · 7 comments
Closed
Labels
can't replicate needs more info not enough information in issue to debug windows

Comments

@VasilisKosmas
Copy link

VasilisKosmas commented Dec 14, 2017

Updated from 1.12.1 to 1.12.7 and still getting the following error when I restart Nodemon after quitting it by CTRL+C using Git Bash.

Port xxxx is already in use
[nodemon] app crashed - waiting for file changes before starting...

The action I take is to kill the running NodeJS proccess through Windows Task Manager and then restart Nodemon. It seems that it cannot kill the child pid properly when CTRL+C is used in my case and on this installation.

However it does not cause any error while I give rs or when it restarts automatically due to monitored files that changed or when I run it through Powershell.

[OS] Windows 10 - Version 1709 (OS Build 16299.125)

[NodeJS] 8.9.0

[Nodemon] 1.12.7

[NPM] 5.5.1

[Git] 2.15.0.windows.1

[MINGW64] MINGW64_NT-10.0 BXDVPC-02 2.9.0(0.318/5/3) 2017-10-05 15:05 x86_64 Msys

[Firewall / Antivirus] None

@remy
Copy link
Owner

remy commented Dec 14, 2017

Not sure what MINGW64, but I've just tried to replicate this in Windows 10 Pro 1703, using git bash and I can't replicate at all. I'll need more details.

capture-nodemon

Left side is gitbash - restarting on file changes, then I did ctrl+c then re-ran and it cleaned up the child process and was able to run again without issue.

@remy remy added can't replicate needs more info not enough information in issue to debug windows labels Dec 14, 2017
@VasilisKosmas
Copy link
Author

VasilisKosmas commented Dec 14, 2017

Running a simple http server exactly as the one you posted, I saw that issue did not get reproduced to me too but it does get reproduced to all other projects that require more modules.

Let me show you one of them

app.js : I removed many dependencies and left only the basics in order to test it only with the followings

const express = require('express')
const session = require('express-session')
const path = require('path')

.bin/www


#!/usr/bin/env node

/**
 * Module dependencies.
 */

var app = require('../app');
var debug = require('debug')('crud-04:server');
var http = require('http');

/**
 * Get port from environment and store in Express.
 */

var port = normalizePort(process.env.PORT || '3100');
app.set('port', port);

/**
 * Create HTTP server.
 */

var server = http.createServer(app);

/**
 * Listen on provided port, on all network interfaces.
 */

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
 * Normalize a port into a number, string, or false.
 */

function normalizePort(val) {
  var port = parseInt(val, 10);

  if (isNaN(port)) {
    // named pipe
    return val;
  }

  if (port >= 0) {
    // port number
    return port;
  }

  return false;
}

/**
 * Event listener for HTTP server "error" event.
 */

function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  var bind = typeof port === 'string'
    ? 'Pipe ' + port
    : 'Port ' + port;

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error(bind + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error(bind + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}

/**
 * Event listener for HTTP server "listening" event.
 */

function onListening() {
  var addr = server.address();
  var bind = typeof addr === 'string'
    ? 'pipe ' + addr
    : 'port ' + addr.port;
  debug('Listening on ' + bind);
}

package.json - On current test I used only the dependencies you can see in app.js

{
  "name": "crud-04",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.18.2",
    "connect-flash": "^0.1.1",
    "cookie-parser": "~1.4.3",
    "debug": "~2.6.9",
    "ejs": "~2.5.7",
    "express": "~4.15.5",
    "express-session": "^1.15.6",
    "morgan": "~1.9.0",
    "mysql": "^2.15.0",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "serve-favicon": "~2.4.5"
  }
}

PS: If necessary you can see MINGW64 version with uname -a

@remy
Copy link
Owner

remy commented Dec 14, 2017

Can you reduce the package down until you've got the minimum replicable case?

@vcarl
Copy link

vcarl commented Dec 15, 2017

Disregard, related to #1173

original comment:


Minimal repro, which I made from OSX: https://github.com/vcarl/nodemon-bug

~/testbench $ git clone git@github.com:vcarl/nodemon-bug.git
// snip
~/testbench $ cd nodemon-bug/
~/t/nodemon-bug (master|✔) $ npm i
// snip
added 321 packages in 3.092s
~/t/nodemon-bug (master|✔) $ npm start

> nodemon-bug@0.0.0 start /Users/vcarl/testbench/nodemon-bug
> nodemon node index.js

[nodemon] 1.13.2
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node node index.js`
Example app listening on port 3000!
rs
[nodemon] app crashed - waiting for file changes before starting...
rs
[nodemon] starting `node node index.js`
Example app listening on port 3000!
rs
[nodemon] app crashed - waiting for file changes before starting...
rs
[nodemon] starting `node node index.js`
Example app listening on port 3000!

I found this issue while trying to hunt down why nodemon was reliably crashing every other restart on my brand new express app. nodemon is pinned to 1.13.2

@remy
Copy link
Owner

remy commented Dec 16, 2017

@vcarl your bug is unrelated to this particular issue, but is related to #1173.

Just to confirm: still waiting on an example for this window bug.

@vcarl
Copy link

vcarl commented Dec 16, 2017

Ah excellent. Thanks for pointing me there.

@no-response no-response bot closed this as completed Dec 21, 2017
@no-response
Copy link

no-response bot commented Dec 21, 2017

This issue has been automatically closed because there hasn't been a response to my request for more information from the original author. With only the information that is currently in the issue, I don't have enough information to take action, sorry! Please comment on this issue if you have or find the answers we need so that someone can investigate further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can't replicate needs more info not enough information in issue to debug windows
Projects
None yet
Development

No branches or pull requests

3 participants