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

Nodemon - app crashes when restarting due to Node already running on that port #1464

Closed
Nmoleo64 opened this issue Nov 25, 2018 · 20 comments
Closed
Labels
can't replicate needs more info not enough information in issue to debug

Comments

@Nmoleo64
Copy link

  • nodemon -v:1.18.6
  • node -v:8.10.0
  • Operating system/terminal environment:
  • Command you ran:

Expected behaviour

Nodemon closes the old Node process and creates a new one

Actual behaviour

Nodemon doesn't stop the old Node process and then the new one crashes because it's trying to run on the same port

Steps to reproduce

Run Nodemon and save the file after making changes


If applicable, please append the --dump flag on your command and include the output here ensuring to remove any sensitive/personal details or tokens.

@jordie23
Copy link

jordie23 commented Nov 26, 2018

I'm having the same issue. I'm finding it hard to find out the cause, because rolling back my shrinkwrap on the project seems to allow it to work, even though version numbers are mostly the same.

The main diff I can see is inside nodemon, the working version is using 1.1.0 of pstree (https://github.com/remy/pstree), while the non-working version is using 1.1.2 of pstree. Also two other pack differences, but looks like there was a change to ps-tree the other day, could that have broken it?

Here are the diff packages:

Non working:

| +-- debug@3.2.6
| | `-- ms@2.1.1
| +-- pstree.remy@1.1.2
| +-- supports-color@5.5.0

Working:

| +-- debug@3.1.0
| | `-- ms@2.0.0 deduped
| +-- pstree.remy@1.1.0
| | `-- ps-tree@1.1.0
| |   `-- event-stream@3.3.4 deduped
| +-- supports-color@5.4.0
| | `-- has-flag@3.0.0

@jordie23
Copy link

jordie23 commented Nov 26, 2018

Just want to follow up. If the ONLY thing I change in my shrinkwrap is the pstree version, which is then used in a docker container and npm runs npm ci, then with version 1.1.2 it will always fail to reload, with 1.1.0 it will always reload successfully.

Looks like 1.1.1 and 1.1.2 were added in quick succession 4 days ago. If I force it to use 1.1.1 nodemon throws this error:

/opt/.../node_modules/nodemon/lib/monitor/run.js:336
        spawn('kill', ['-s', sig, child.pid].concat(kids.map(p => p.PID)))
                                                         ^
TypeError: Cannot read property 'map' of undefined
    at /opt/.../node_modules/nodemon/lib/monitor/run.js:336:58
    at /opt/.../node_modules/pstree.remy/lib/tree.js:53:11
    at ChildProcess.onClose (/opt/.../node_modules/pstree.remy/lib/tree.js:80:9)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at maybeClose (internal/child_process.js:925:16)
    at Socket.stream.socket.on (internal/child_process.js:346:11)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at Pipe._handle.close [as _onclose] (net.js:557:12)

@remy

@RoyalHunt
Copy link

Found same solution... With "pstree.remy": "1.1.0" which use ps-tree library it is work fine.

@0x-leen
Copy link

0x-leen commented Nov 26, 2018

My solution:

yarn add kill-port

in nodemon.json:

{
  "events": {
    "restart": "kill-port 5000",
    "crash": "kill-port 5000"
  },
  "delay": "1500"
}

Replace your port:

"restart": "kill-port [my port]",

@murrayju
Copy link

murrayju commented Nov 27, 2018

@RoyalHunt be careful with rolling back pstree.remy, that upgrade eliminated malicious code in the dependency tree. See #1442 and also dominictarr/event-stream#116.

@remy any idea what is causing this bug? Breaks my entire workflow that depends on nodemon restarts...

edit:
My workaround is to hack up my yarn.lock to resolve pstree.remy@1.1.0 and event-stream@3.3.4 (which contains the patch to eliminate the infected flatmap-stream). This seems to be working for now.

@jordie23
Copy link

@murrayju Thanks for the heads up. Did the same, restricted ours to pstree.remy@1.1.0 and event-stream@3.3.4. Not using yarn, I set these in our top level package.json file and rebuilt our shrinkwrap, and because NPM likes to dedup it'll use these versions for other packages that have them as deps and matches the semver.

@remy
Copy link
Owner

remy commented Nov 27, 2018

I need to know your OS…

@remy remy added can't replicate needs more info not enough information in issue to debug labels Nov 27, 2018
@ravidhu
Copy link

ravidhu commented Nov 27, 2018

i have this problem with :
Ubuntu 18.04
node 8.13.0

@remy
Copy link
Owner

remy commented Nov 27, 2018

@ravid87 do you have a pared down version of a script that I can replicate with?

I'm using this in ubuntu (in docker) and I can't replicate either when it's a triggered restart or rs restart:

const express = require('express');

const app = express();

app.use((req, res, next) => {
    res.send('<h1>Hello from Express!</h1>');
});

app.listen(3000)

@ravidhu
Copy link

ravidhu commented Nov 27, 2018

@remy

https://github.com/ravid87/testmon

you just have to run : yarn run dev

@remy
Copy link
Owner

remy commented Nov 27, 2018

Track here #1463 (comment)

@slymbo
Copy link

slymbo commented Aug 5, 2019

Change the port to any other port number, just not 3000.
for exemple make it 5000 or 4000 it will be okay

with port = 4000
image


With port = 3000
image

@aymather
Copy link

I am still having this problem using Node v8.11.3, on MacOS 10.14.3.

@slymbo
Copy link

slymbo commented Aug 13, 2019

@aymather u need to kill the process work on the port for exemple 3000 and restart everything.Or u will take my idea, that mean u will change the port every time when u have the same problem.

@aymather
Copy link

aymather commented Aug 13, 2019

@arabrain When I tried restarting on different ports I still had the same issue. Right now my fix is to use the following command in the command line: lsof -ti tcp:5000 | xargs kill and then running npm run dev but even then sometimes I'll get the same error.

@aodr3w
Copy link

aodr3w commented Nov 18, 2019

do this in package.json
"scripts": {
"start": "node server",
"server": "fuser -k 8000/tcp && nodemon server"
},
this will kill the old process running on port8080 before nodemon restarts

@TCarmine
Copy link

This is happening again. I am wondering if the fix introduced https://github.com/remy/nodemon/commit/c05d2d1e3a1977692d36def8c5d64c73046965c1 has again been overrided wrongly

@TCarmine
Copy link

TCarmine commented Nov 22, 2019

for the moment similar to aymather , I am killing forcely all the process on that port with sudo kill -9 $(sudo lsof -t -i:3000) and I put that in the package.json script that I run on my convenience (like clean):

scripts": {
   "clean":"kill -9 $(lsof -t -i:3000)"
 },

@remy
Copy link
Owner

remy commented Nov 23, 2019

@TCarmine if you're seeing a new issue you'll want to create a new issue (even though it has similar symptoms to this issue raised last year). You'll also need to make sure you're on the latest nodemon, currently 2.0.1

@remy
Copy link
Owner

remy commented Nov 23, 2019

I'm going to lock this issue to encourage any new issues into new (and monitored) discussion 👍

Repository owner locked as resolved and limited conversation to collaborators Nov 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
can't replicate needs more info not enough information in issue to debug
Projects
None yet
Development

No branches or pull requests