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

v15 express address already in use on restart #14006

Closed
kizzlebot opened this issue Dec 23, 2022 · 10 comments
Closed

v15 express address already in use on restart #14006

kizzlebot opened this issue Dec 23, 2022 · 10 comments

Comments

@kizzlebot
Copy link

Current Behavior

If you create a brand new nx project with the express preset, if you start the express app and change a source file to restart the server the following error is shown

Error: listen EADDRINUSE: address already in use :::3333

Expected Behavior

When the express server restarts, it should wait for the previous process to terminate before attempting to restart the server and should be able to restart on the same port number

Github Repo

https://github.com/kizzlebot/nx-bug-report-example

Steps to Reproduce

  1. Create a new express project using nx working v15
    npx create-nx-workspace@15.x.x --preset=express
  2. Change directory to the project
  3. Start express server
  4. Make a change to the source file
  5. Observe the following is shown
    image

Nx Report

Node : 16.15.1
   OS   : linux x64
   npm  : 8.11.0

   nx : 15.4.1
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.4.1
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.4.1
   @nrwl/expo : Not Found
   @nrwl/express : 15.4.1
   @nrwl/jest : 15.4.1
   @nrwl/js : 15.4.1
   @nrwl/linter : 15.4.1
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 15.4.1
   @nrwl/nx-cloud : 15.0.2
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 15.4.1
   @nrwl/workspace : 15.4.1
   @nrwl/vite : Not Found
   typescript : 4.8.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Failure Logs

![image](https://user-images.githubusercontent.com/2028917/209391509-f096f81e-4675-4985-873e-7aa2bd605ac3.png)

> nx run api:serve --inspect=false                               
                                                                                                                                                 
chunk (runtime: main) main.js (main) 678 bytes [entry] [rendered]                       
webpack compiled successfully (53a71045fd762d8e)                                         
Type-checking in progress...                                               
Listening at http://localhost:3333/api                                                        
No errors found.                                                                    
chunk (runtime: main) main.js (main) 678 bytes [entry] [rendered]                    
webpack compiled successfully (f7418c85cc8742ab)                                                    
Type-checking in progress...                                                                                                                                                                                                                                                      
No errors found.                                                                  
Error: listen EADDRINUSE: address already in use :::3333                                                                                                                                                                                                                          
    at Server.setupListenHandle [as _listen2] (node:net:1372:16)                                                                                                            
    at listenInCluster (node:net:1420:12)                                                             
    at Server.listen (node:net:1508:7)                                                                                                       
    at Function.listen (/home/jchoi/Documents/merlion-solutions/research/nx-express/node_modules/express/lib/application.js:635:24)
    at /home/jchoi/Documents/merlion-solutions/research/nx-express/dist/apps/api/webpack:/nx-express/apps/api/src/main.ts:20:20
    at /home/jchoi/Documents/merlion-solutions/research/nx-express/dist/apps/api/main.js:69:3    
    at Object.<anonymous> (/home/jchoi/Documents/merlion-solutions/research/nx-express/dist/apps/api/main.js:74:12)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)                                                                            
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32) {                               
  code: 'EADDRINUSE',                                                            
  errno: -98,                                                    
  syscall: 'listen',                                                                                                                             
  address: '::',                                                                        
  port: 3333                                                                             
}

Additional Information

This issue is occurring because of this Map.

The key of the Map is an instance of a array when the value is set. When the value is retrieved it creates a new array instance containing the same elements and uses it to retrieve the value. The issue is the key is using two different references even though they contain the same elements.

const hashedMap = new Map();
const pid = 'abcd';
const hashedKey = [pid];



hashedMap.set(hashedKey, 'some-value');


hashedMap.get(hashedKey);   // -> 'some-value'
hashedMap.get([pid]);              // -> undefined (will not work)
@iamgbayer
Copy link

this is happening to me creating a new nestjs application too

@impcyber
Copy link

impcyber commented Dec 25, 2022

The same thing happens when using fastify + @nestjs/fastify-adapter

   Node : 19.2.0
   OS   : linux x64
   npm  : 8.19.3
   
   nx : 15.4.1
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.4.1
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.4.1
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.4.1
   @nrwl/js : 15.4.1
   @nrwl/linter : 15.4.1
   @nrwl/nest : 15.4.1
   @nrwl/next : Not Found
   @nrwl/node : 15.4.1
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 15.4.1
   @nrwl/workspace : 15.4.1
   @nrwl/vite : Not Found
   typescript : 4.9.4

image

@impcyber
Copy link

With @nrwl/js@15.3.3 works fine

@AgentEnder
Copy link
Member

PR fixing this was merged

@alex-w0
Copy link

alex-w0 commented Jan 29, 2023

I still get the error on my nestjs project and I use the version "nx": "15.6.3"

@AgentEnder
Copy link
Member

I still get the error on my nestjs project and I use the version "nx": "15.6.3"

@alex-w0 whats nx report say

@alex-w0
Copy link

alex-w0 commented Jan 29, 2023

@AgentEnder Here's the report, the project was also created from scratch:

nx report

 >  NX   Report complete - copy this into the issue template

   Node : 18.12.1
   OS   : linux x64
   npm  : 8.19.2
   
   nx : 15.6.3
   @nrwl/angular : Not Found
   @nrwl/cypress : Not Found
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.6.3
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.6.3
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.6.3
   @nrwl/js : 15.6.3
   @nrwl/linter : 15.6.3
   @nrwl/nest : 15.6.3
   @nrwl/next : Not Found
   @nrwl/node : 15.6.3
   @nrwl/nx-cloud : 15.0.2
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : Not Found
   @nrwl/webpack : 15.6.3
   @nrwl/workspace : 15.6.3
   @nrwl/vite : Not Found
   typescript : 4.9.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

@AgentEnder
Copy link
Member

Can you open a new issue including repro steps? The problem in this issue was addressed and confirmed as fixed, and it's hard to keep track of reports on closed issues.

@alex-w0
Copy link

alex-w0 commented Jan 29, 2023

@AgentEnder New issue is created, if you need a repository to reproduce the bug, let me know so I can provide it, but should be the same one as in this issue.

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants