Skip to content

pstree vuln / pstree upgrade / Error: listen EADDRINUSE: address already in use #1463

@alex996

Description

@alex996
  • nodemon -v: 1.18.6
  • node -v: 11.2.0
  • npm -v: 6.4.1
  • yarn -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

  1. yarn init -y
  2. yarn add express and yarn add -D nodemon
  3. touch app.js and touch lib.js (see file contents below)
  4. dev script in package.json with nodemon -r ./lib app
  5. yarn 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 yarn and npm, i.e. npm run dev produces the save error
  • it works when using require('./lib') in app.js instead of -r from the CLI
  • it works either way without express or any web server (because the port is not used)
  • same issue in Node 11.2.0, 11.1.0, and 10.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
> [email protected] 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' } }
--------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions