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

EADDRINUSE in 2.0.12 version #1893

Closed
DzenDyn opened this issue Jul 14, 2021 · 37 comments
Closed

EADDRINUSE in 2.0.12 version #1893

DzenDyn opened this issue Jul 14, 2021 · 37 comments

Comments

@DzenDyn
Copy link

DzenDyn commented Jul 14, 2021

Nodemon version 2.0.12
run nodemon after change or rs i have error:
Error: listen EADDRINUSE: address already in use :::3007

`events.js:291
throw er; // Unhandled 'error' event
^

Error: listen EADDRINUSE: address already in use :::3007
at Server.setupListenHandle [as _listen2] (net.js:1316:16)
at listenInCluster (net.js:1364:12)
at Server.listen (net.js:1450:7)
at Object. (C:\Users\Nikiforov.Evgeny\Documents\projects\passport\bin\app.js:35:15)
at Module._compile (internal/modules/cjs/loader.js:1256:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1277:10)
at Module.load (internal/modules/cjs/loader.js:1105:32)
at Function.Module._load (internal/modules/cjs/loader.js:967:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1343:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'EADDRINUSE',
errno: -4091,
syscall: 'listen',
address: '::',
port: 3007
}
`

When i rollback to version 2.0.7 - i have no errors.

Setps to reproduce:

app.js:

import express from 'express';
const server = express();

server.use(express.urlencoded({ extended: true }));
server.use(express.json());

server.listen(3007, () => {
    console.info(
        'Listening on http://localhost\nOpen http://localhost/v1/api-docs for documentation'
    );
});

package.json:

{
  "name": "nodemontest",
  "version": "1.0.0",
  "description": "test nodemon error eaddrinuse",
  "main": "app.js",
  "license": "MIT",
  "type": "module",
  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {
    "nodemon": "^2.0.7"
  },
  "scripts": {
    "server": "node ./src/app.js",
    "watch": "nodemon"
  }
}

nodemon.json:

{ 
    "watch": ["src/*"],
    "ext": "js, json, yaml",
    "exec": "yarn server"
}
  1. yarn watch
  2. wait while server run
  3. type rs and press enter or add some comment to app.js

I have Node.js v14.7.0.
Windows 10 Version 1903 (Build 18362.239)
Powershell version 5.1.18362.145

The usual windows command line (cmd.exe) has the same error. It looks like it's not about the terminal.

@remy
Copy link
Owner

remy commented Jul 14, 2021

Can you add in the prerequisite details in the initial issue - so I know what versions, etc (not the nodemon version).

@remy remy added the needs more info not enough information in issue to debug label Jul 14, 2021
@remy
Copy link
Owner

remy commented Jul 14, 2021

You're going to need to pare that down. Plus, I've not idea what hpt-backend is.

Also, I don't know what version of Windows or node you're using. Or what shell...

@remy remy added windows and removed needs more info not enough information in issue to debug labels Jul 14, 2021
@DzenDyn
Copy link
Author

DzenDyn commented Jul 14, 2021

Simplified code and package.json to a minimum (1 post updated) and still run into error.

@remy
Copy link
Owner

remy commented Jul 14, 2021

Yeah, I can replicate now, but I strongly suspect it's because you've got nodemon on top of about 5 or 6 so nested processes. I'm just reworking the package undo that...

@remy
Copy link
Owner

remy commented Jul 14, 2021

Screenshot 2021-07-14 at 14 25 01

I know this doesn't solve your problem but this confirms it's stacking yarn on top of nodemon on top of yarn on top of npm-run-all on top of … I'm losing track, but that's the issue...

@DzenDyn
Copy link
Author

DzenDyn commented Jul 14, 2021

Im clean and delete all of scripts and still run into error. Check 1 post – i edited it.

@DzenDyn
Copy link
Author

DzenDyn commented Jul 14, 2021

Looks like it is windows only error. Cant reproduce it on ubuntu 20.04 and node version 16.5.0. Will try to update node on windows to 16.5.0 and test it again.

@remy
Copy link
Owner

remy commented Jul 14, 2021

ACK - will check with updated info 👍

@DzenDyn
Copy link
Author

DzenDyn commented Jul 14, 2021

Checked windows 10, node 16.5.0 - same issue. Looks like its Windows only issue.

@HaeusslerAdrian
Copy link

I have a similar problem, but it exists since Version 2.0.8, and every following version. Did these versions work fine for you? @DzenDyn
My problem also exists only on windows, my colleagues on linux & mac don't have that issue. (I'm trying to figure out if we have the same error or if I should create a new github-issue)

@DzenDyn
Copy link
Author

DzenDyn commented Jul 15, 2021

I have a similar problem, but it exists since Version 2.0.8, and every following version. Did these versions work fine for you? @DzenDyn
My problem also exists only on windows, my colleagues on linux & mac don't have that issue. (I'm trying to figure out if we have the same error or if I should create a new github-issue)

Yes it started from 2.0.8. Looks like same issue

@levirs565
Copy link

You can fix this issue by downgrading nodemon to version 2.0.7.

@Aareksio
Copy link

Aareksio commented Jul 22, 2021

Minimum reproduction (via npm) in repo for convenience: https://github.com/Aareksio/nodemon-bug-2.0.8

This is degradation between 2.0.7 and 2.0.8 (probably 500c1b0)
Only breaks when launching script through middleman process (tested with npm, yarn, ts-node)

I do not know much about how the signals work, but if they do not propagate down, I fear it may be infeasible to find exact process in the chain we need to SIGINT. Running https://github.com/remy/nodemon/blob/main/lib/monitor/run.js#L345-L351 recursively may reveal the bottom-most process, but it may not be necessarily the one that needs to be SIGINTed.

Perhaps reverting to old behavior behind an optional flag (here: https://github.com/remy/nodemon/blob/main/lib/monitor/run.js#L327) is a solution to avoid downgrading to 2.0.7 until it's fixed for good?

@DzenDyn
Copy link
Author

DzenDyn commented Jul 23, 2021

@Aareksio one of solutions – migrate to wsl2, and run project into linux enviroment with latest nodemon, or downgrade to 2.0.7.
Looks like there is no security issue in 2.0.7

@remy
Copy link
Owner

remy commented Jul 27, 2021

Can we try with [email protected] aka npm install -g nodemon@debug - I've moved the try/catch to a different point.

@DzenDyn
Copy link
Author

DzenDyn commented Jul 27, 2021

@remy hello! Just tried. Ran into same error.

Node.js v16.5.0
express ^4.17.1
nodemon 2.0.13-alpha.1

2 0 13-alpha 1

@remy
Copy link
Owner

remy commented Jul 27, 2021

@DzenDyn for my own sanity, can you strip yarn from the process and run only nodemon app.js (assuming you're testing with the example code)?

@Aareksio
Copy link

Aareksio commented Jul 27, 2021

@remy https://github.com/Aareksio/nodemon-bug-2.0.8

The issue is with running the node script through proxy (such as npm, yarn or ts-node). It works well when calling nodemon app.js directly.

1. npm run dev -> nodemon

image

2. npx nodemon index.js

image

The problem is in this code finding proxy process - the first child, not the main script.

@DzenDyn
Copy link
Author

DzenDyn commented Jul 27, 2021

@DzenDyn for my own sanity, can you strip yarn from the process and run only nodemon app.js (assuming you're testing with the example code)?

@remy i did it. And it works.
But why? It worked with startup scripts earlier =\

@remy
Copy link
Owner

remy commented Jul 27, 2021

Okay, we're making some progress then. The "fix" that was put in place in 2.0.8 was specifically to handle spawned sub-processes, but it looks like in the cases you're seeing it's not actually stopping the process.

This is good though, it helps narrow the issue.

@remy
Copy link
Owner

remy commented Jul 27, 2021

Okay, I can finally replicate.

For the moment, can you both: @DzenDyn and @Aareksio test by removing the exec prop in your nodemon.json files - I think that's what is at play here.

@Aareksio
Copy link

Aareksio commented Jul 27, 2021

@remy Yes, removing "exec" prop does work in the minimalistic example. What if we need more complex "exec" command though? For example we want to add -r dotenv/config.

@DzenDyn
Copy link
Author

DzenDyn commented Jul 27, 2021

@remy Yes, removing "exec" prop does work in the minimalistic example. What if we need more complex "exec" command though? For example we want to add -r dotenv/config.

@remy I confirm.

@remy
Copy link
Owner

remy commented Jul 27, 2021

@remy Yes, removing "exec" prop does work in the minimalistic example. What if we need more complex "exec" command though? For example we want to add -r dotenv/config.

You can pass -r directly to nodemon, but that's not the point - now I know where to look for the issue and how to confirm any fixes.

@phibersoft
Copy link

I'm getting same error on V2.0.7 too.
Methods like "kill-port" work to get rid of this problem, but I'm happy to use the V1.19.4 for now.

@bennycode
Copy link

I recently upgraded nodemon from v2.0.7 (which worked just fine!) to v2.0.12.

Now (with v2.0.12) I am seeing a lot of errors on Windows 10 when nodemon restarts my server:

Started server on port "3000".
Error: listen EADDRINUSE: address already in use 127.0.0.1:3000
    at Server.setupListenHandle [as _listen2] (node:net:1315:16)
    at listenInCluster (node:net:1363:12)
    at doListen (node:net:1501:7)
    at processTicksAndRejections (node:internal/process/task_queues:84:21) {
  code: 'EADDRINUSE',
  errno: -4091,
  syscall: 'listen',
  address: '127.0.0.1',
  port: 3000
}

Here is what my nodemon.json config looks like:

{
  "exec": "yarn start:server",
  "ext": "ts",
  "signal": "SIGHUP"
}

And this is my yarn start:server command:

"start:server": "ts-node src/start/startServer.ts"

The startServer.ts script does the following:

import 'dotenv-defaults/config';
import 'reflect-metadata';
import {NestServer} from '../server/NestServer';

async function start(): Promise<void> {
  const server = new NestServer();
  await server.start();
}

start().catch(error => {
  console.error(error);
  process.exit(1);
});

@cckelly
Copy link

cckelly commented Sep 19, 2021

I'm getting this on OSX too so I don't think it's exclusively Windows. Any update here?

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