nodemon: pstree vuln / pstree upgrade / Error: listen EADDRINUSE: address already in use
nodemon -v: 1.18.6node -v: 11.2.0npm -v: 6.4.1yarn -v: 1.12.3- OS / terminal: Ubuntu 18.10 cosmic (linux x64) / Bash
- Command:
nodemon -r ./lib app
I’m running into an EADDRINUSE error with nodemon and express since yesterday, which only happens when requiring a module (or file) using -r from the CLI.
Expected behaviour
It should restart the web server when the entry file is saved.
Actual behaviour
It hangs up with Error: listen EADDRINUSE: address already in use when the file is saved.
Steps to reproduce
yarn init -yyarn add expressandyarn add -D nodemontouch app.jsandtouch lib.js(see file contents below)devscript inpackage.jsonwithnodemon -r ./lib appyarn dev
// app.js
require('express')().listen(3000, () => console.log('Works'))
// lib.js - empty
"scripts": {
"dev": "nodemon -r ./lib app"
},
"dependencies": {
"express": "^4.16.4"
},
"devDependencies": {
"nodemon": "^1.18.6"
}
When I run yarn dev from the terminal, and then do Ctrl+S in app.js or lib.js in the editor, I get
yarn run v1.12.3
$ nodemon -r ./lib app
[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `node -r ./lib app index.js`
Works
[nodemon] restarting due to changes...
[nodemon] starting `node -r ./lib app index.js`
events.js:167
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1294:14)
at listenInCluster (net.js:1342:12)
at Server.listen (net.js:1429:7)
at Function.listen (/path/to/my/app/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/path/to/my/app/app.js:1:84)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
Emitted 'error' event at:
at emitErrorNT (net.js:1321:8)
at internalTickCallback (internal/process/next_tick.js:72:19)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:778:11)
at startup (internal/bootstrap/node.js:300:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:826:3)
[nodemon] app crashed - waiting for file changes before starting...
The app boots correctly, but as soon as any file changes, nodemon can’t restart it. In the meantime, the app still continues to run in the background. If I do Ctrl+C, it quits, but there’s no more process on port 3000, so killing it by port fuser -k 3000/tcp doesn’t do anything.
I found that
- it doesn’t work with both
yarnandnpm, i.e.npm run devproduces the save error - it works when using
require('./lib')inapp.jsinstead of-rfrom the CLI - it works either way without
expressor any web server (because the port is not used) - same issue in Node
11.2.0,11.1.0, and10.13.0
I discovered this through esm when doing nodemon -r esm app, but later found out that it happens with any file. From that thread, the issue also seems to happen on MacOS as well. Tried rebooting, reinstalling Node, removing yarn.lock, then removing and re-installing node_modules, locking to older versions of nodemon, and express… I’m out of options here.
I scavenged many threads in this repo with this same error, but to no avail. I hope I’m posting in the right repo this time. Any help is appreciated, thanks!
P.S. Here’s the dump with nodemon -r ./lib app --dump just in case.
Click to expand
> app@1.0.0 dev /path/to/my/app
> nodemon -r ./lib app --dump
[nodemon] 1.18.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
--------------
node: v11.2.0
nodemon: 1.18.6
command: /home/alex/.nvm/versions/node/v11.2.0/bin/node /path/to/my/app/node_modules/.bin/nodemon -r ./lib app --dump
cwd: /path/to/my/app
OS: linux x64
--------------
{ run: false,
system: { cwd: '/path/to/my/app' },
required: false,
dirs: [ '/path/to/my/app' ],
timeout: 1000,
options:
{ dump: true,
ignore:
[ '**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**',
re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/ ],
watch: [ '*.*', re: /.*\..*/ ],
ignoreRoot:
[ '**/.git/**',
'**/.nyc_output/**',
'**/.sass-cache/**',
'**/bower_components/**',
'**/coverage/**',
'**/node_modules/**' ],
restartable: 'rs',
colours: true,
execMap: { py: 'python', rb: 'ruby' },
stdin: true,
runOnChangeOnly: false,
verbose: false,
signal: 'SIGUSR2',
stdout: true,
watchOptions: {},
execOptions:
{ script: 'index.js',
exec: 'node',
args: [ '-r', './lib', 'app' ],
scriptPosition: 3,
nodeArgs: undefined,
execArgs: [],
ext: 'js,mjs,json',
env: {} },
monitor:
[ '*.*',
'!**/.git/**',
'!**/.nyc_output/**',
'!**/.sass-cache/**',
'!**/bower_components/**',
'!**/coverage/**',
'!**/node_modules/**' ] },
load: [Function],
reset: [Function: reset],
lastStarted: 0,
loaded: [],
watchInterval: null,
signal: 'SIGUSR2',
command:
{ raw:
{ executable: 'node',
args: [ '-r', './lib', 'app', 'index.js' ] },
string: 'node -r ./lib app index.js' } }
--------------
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 10
- Comments: 28 (9 by maintainers)
Commits related to this issue
- fix: killing all sub processes Fixes #1463 Fixes #1469 Fixes #1464 — committed to remy/nodemon by remy 6 years ago
- fix: upgrade pstree to remove vulnerability Fixes #1463 Fixes #1469 Fixes #1464 Completely removes the old method of `pstree[.remy]` and drops the event-stream vuln at the same time. — committed to remy/nodemon by remy 6 years ago
Same behavior with lts/boron and lts/carbon. Tried with nodemon 1.18.x & 1.17.x.
Also happens when
nodemon --exec.Debian 4.18.10-2 x86_64
Strange.
Edit:
--signal SIGTERMor--delay 1500msdo not change behavior.Edit2: I am now using a bootstrap.js instead of the -r flag yet I still get the above error when restarting (simple edit). There is a db conn and an http server in the app. It feels like the server holds onto the db conn and thus nodemon can’t terminate it.
The problem is in
pstree.remy. It was recently published to1.1.2, which brokenodemonfor many people (#1463, #1464, #1466).nodemondepends on it viapstree.remy "^1.1.0". Note the^symbol; it tells npm to pull the latest1.x.x, in this case,1.1.2, and not1.1.0.If you go to
yarn.lock, change frompstree.remy "^1.1.0"topstree.remy "1.1.0"(no caret), removepstree.remy@^1.1.0:block altogether, and re-runyarn, it installs the older working version, and reload will be back to normal. The props go to @jordie23 for finding this out.@Himself65 you need to bump to nodemon@1.18.8
Thankfully I’ve landed on this issue and bumped to 1.18.7 - I was already on course to spending days on this!
(On Monday eve we’ve bumped to 1.18.6 but had to disable the tests in order to publish; last night we’ve bumped to 1.18.7 and reinstated the tests).
Have a look at the tests for the plugin and let me know if you think porting them here is viable.
Okay, I’m finally able to replicate. It needs nodemon to be spawned inside of an
npm runcommand.