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

pseudo IPC socket is not deleted resulting in Error: listen EADDRINUSE: address already in use /tmp/xxx/fpxxx.sock #21610

Open
2 of 4 tasks
Markus-Ende opened this issue Feb 5, 2024 · 14 comments
Assignees
Labels

Comments

@Markus-Ende
Copy link

Current Behavior

We run our local dev environment using docker compose. While doing so, we get this error message after restarting: Error: listen EADDRINUSE: address already in use /tmp/somefolder/fpXX.sock (XX depending on process id).
After some debugging I found out, that the .sock file is not properly deleted between runs.

As a workaround, this issue can be fixed by adding this line to the top of psuedo-ipc.js#init() (https://github.com/nrwl/nx/blob/master/packages/nx/src/tasks-runner/psuedo-ipc.ts#L42):

const fs = require("fs");
fs.existsSync(this.path) && fs.unlinkSync(this.path); // remove fpXX.sock file if existing

The problem doesn't occur when not using docker compose, probably, because there the PID is changed more frequently. Or maybe an appropriate close hook is not called properly.

Expected Behavior

I should be able to re-start docker compose environment / fpXX.sock files should be properly cleaned.

GitHub Repo

No response

Steps to Reproduce

  1. create docker compose file that starts an nx serve task
  2. start docker compose
  3. Stop docker compose (using Ctrl + c)
  4. re-start docker compose

If you really need a repo to reproduce, I can provide one, but it is currently not straight-forward for me to create a workspace due to this issue: #20270

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 20.11.0
   OS     : linux-x64
   npm    : 10.2.4
   
   nx                 : 17.3.2
   @nx/js             : 17.3.2
   @nx/jest           : 17.3.2
   @nx/linter         : 17.3.2
   @nx/eslint         : 17.3.2
   @nx/workspace      : 17.3.2
   @nx/angular        : 17.3.2
   @nx/cypress        : 17.3.2
   @nx/devkit         : 17.3.2
   @nx/eslint-plugin  : 17.3.2
   @nx/nest           : 17.3.2
   @nx/node           : 17.3.2
   @nx/playwright     : 17.3.2
   @nx/plugin         : 17.3.2
   @nx/storybook      : 17.3.2
   @nrwl/tao          : 17.3.2
   @nx/web            : 17.3.2
   @nx/webpack        : 17.3.2
   typescript         : 5.3.3
   ---------------------------------------
   Community plugins:
   @ionic/angular               : 7.7.0
   @ngrx/component-store        : 17.0.1
   @ngrx/effects                : 17.0.1
   @ngrx/entity                 : 17.0.1
   @ngrx/router-store           : 17.0.1
   @ngrx/schematics             : 17.0.1
   @ngrx/store                  : 17.0.1
   @ngrx/store-devtools         : 17.0.1
   @nxext/capacitor             : 15.7.0
   @nxext/ionic-angular         : 15.7.0
   @qupaya/nestjs-ng-universal  : 8.0.2
   @storybook/angular           : 7.6.10
   @testing-library/angular     : 15.2.0
   @trumbitta/nx-plugin-openapi : 1.12.1
   ---------------------------------------
   Local workspace plugins:
         @qupaya/workspace-plugin

Failure Logs

2024-02-05 16:25:05 node:events:496
2024-02-05 16:25:05       throw er; // Unhandled 'error' event
2024-02-05 16:25:05       ^
2024-02-05 16:25:05 
2024-02-05 16:25:05 Error: listen EADDRINUSE: address already in use /tmp/f53b52ad6d21cceb72df/fp25.sock
2024-02-05 16:25:05     at Server.setupListenHandle [as _listen2] (node:net:1855:21)
2024-02-05 16:25:05     at listenInCluster (node:net:1920:12)
2024-02-05 16:25:05     at Server.listen (node:net:2025:5)
2024-02-05 16:25:05     at /app/node_modules/nx/src/tasks-runner/psuedo-ipc.js:49:25
2024-02-05 16:25:05     at new Promise (<anonymous>)
2024-02-05 16:25:05     at PsuedoIPCServer.init (/app/node_modules/nx/src/tasks-runner/psuedo-ipc.js:40:16)
2024-02-05 16:25:05     at ForkedProcessTaskRunner.init (/app/node_modules/nx/src/tasks-runner/forked-process-task-runner.js:32:30)
2024-02-05 16:25:05     at TaskOrchestrator.run (/app/node_modules/nx/src/tasks-runner/task-orchestrator.js:37:44)
2024-02-05 16:25:05     at runAllTasks (/app/node_modules/nx/src/tasks-runner/default-tasks-runner.js:27:25)
2024-02-05 16:25:05     at defaultTasksRunner (/app/node_modules/nx/src/tasks-runner/default-tasks-runner.js:18:22)
2024-02-05 16:25:05 Emitted 'error' event on Server instance at:
2024-02-05 16:25:05     at emitErrorNT (node:net:1899:8)
2024-02-05 16:25:05     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
2024-02-05 16:25:05   code: 'EADDRINUSE',
2024-02-05 16:25:05   errno: -98,
2024-02-05 16:25:05   syscall: 'listen',
2024-02-05 16:25:05   address: '/tmp/f53b52ad6d21cceb72df/fp25.sock',
2024-02-05 16:25:05   port: -1
2024-02-05 16:25:05 }

Package Manager Version

npm@10.2.4

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

tried on macOS and WSL2

@AgentEnder AgentEnder added the scope: core core nx functionality label Feb 5, 2024
@derekkite
Copy link

derekkite commented Feb 6, 2024

A workaround is to run docker-compose up --force-recreate

Something to investigate is if you are getting an error when you stop the docker image. I'm getting dev-sockets exited with code 137which is possibly a memory issue in the images. The way that I found this was to start the docker-compose in one terminal and run docker-compose stop in another, then watch the shutdown in the first terminal.

@MarcRoemmelt
Copy link

I can confirm this issue on Linux.

It started occurring when we migrated to NX v18.

On v17.0.3 we don't run into this issue.

@jokeyrhyme
Copy link

We're encountering this issue in a containerised CI environment, after updating nx from 16.x to 17.3.2

@jaknas
Copy link

jaknas commented Mar 6, 2024

We're encountering this issue in a containerised CI environment, after updating nx from 16.x to 17.3.2

Same here, but with Nx 18.0.5

@dtap001
Copy link

dtap001 commented Mar 6, 2024

same

@chafnan
Copy link

chafnan commented Mar 12, 2024

The fix that @Markus-Ende suggested worked for me.

I used yarn to patch nx (v18.0.8) and problem went away.

@eschelfhoutoxya
Copy link

Had the same issue on Windows with Nx 18.0.8

@karol-f
Copy link

karol-f commented Mar 20, 2024

+1, Nx 18.0.8, While deploying and running in Docker on Fly.io

@vamidi
Copy link

vamidi commented Apr 16, 2024

+1, Same issue on Mac with Nx 18.0.8

@karol-f
Copy link

karol-f commented Apr 16, 2024

While waiting for the fix, please use NPM library Patch Package with the following Git patch:

diff --git a/node_modules/nx/src/tasks-runner/psuedo-ipc.js b/node_modules/nx/src/tasks-runner/psuedo-ipc.js
index c2a631a..f8f90f0 100644
--- a/node_modules/nx/src/tasks-runner/psuedo-ipc.js
+++ b/node_modules/nx/src/tasks-runner/psuedo-ipc.js
@@ -17,6 +17,7 @@
  *     * channel = getPsuedoIpcChannel(process.env.NX_IPC_CHANNEL_ID)
  *     * forkChildProcess.on('message', writeToPsuedoIpcChannel)
  */
+const fs = require("fs");
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.PsuedoIPCClient = exports.PsuedoIPCServer = void 0;
 const net_1 = require("net");
@@ -29,6 +30,7 @@ class PsuedoIPCServer {
         this.childReadyMap = new Map();
     }
     init() {
+        fs.existsSync(this.path) && fs.unlinkSync(this.path); // remove fpXX.sock file if existing
         return new Promise((res) => {
             this.server = new net_1.Server((socket) => {
                 this.sockets.add(socket);

@darlanalves
Copy link

@darlanalves
Copy link

Another possible fix, without patching NX, while this issue is open:

  • set NX_DAEMON_SOCKET_DIR to a folder under control of the current build scripts.
  • before starting NX, run a command to remove any file that matches fp*.sock in that folder, or generate a random folder name in every run, to avoid conflicts between multiple runners

See socket-utils.ts and tmp-dir.ts for more info.

@vergilfromadyen
Copy link
Contributor

vergilfromadyen commented Jul 12, 2024

There are multiple issues here, and one seems to be with the path length. I fixed the issue by setting NX_DAEMON_SOCKET_DIR to /tmp.

I see @AgentEnder is assigned to this, maybe a try-catch to try a shorter socket dir would sorta work?
Unfortunately I can't give you details about OS and platforms, but potentially running it on a recent-ish Rocky 8 Linux would yield similar results. For me it was breaking with a path length of 119 chars (Linux has a 108-char path limit, Windows has a MAX_PATH constant which is 256ish characters). So some validation should be in there.

We also tried mounting a container with -v /path/to/something/long/tmp:/tmp/, then setting the NX_DAEMON_SOCKET_DIR inside the container to /tmp/ to test if the host environment would reject a path like that. This seems to work well so OP's issue may be different.

Created #26936 to address the path length part of the issue.

Copy link

This issue has been automatically marked as stale because it hasn't had any activity for 6 months.
Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore.
If at this point, this is still an issue, please respond with updated information.
It will be closed in 21 days if no further activity occurs.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests