nitro icon indicating copy to clipboard operation
nitro copied to clipboard

worker: listen EADDRINUSE: address already in use

Open pi0 opened this issue 2 years ago • 11 comments

Context: https://github.com/nuxt/nuxt/issues/13587

This error often happens randomly with dev server running in a container.

pi0 avatar Jan 26 '23 10:01 pi0

The most common occurrence of this error is when using Nuxt in Docker. A temporary workaround is to add the command rm -rf /tmp/nitro/worker-* to the entrypoint, before running pnpm run dev

misaon avatar Jan 26 '23 11:01 misaon

Context: nuxt/nuxt#13587

This error often happens randomly with dev server running in a container.

Actually not "often", I have this bug on every container restart.

Intevel avatar Jan 26 '23 15:01 Intevel

My current work around in nuxt is to just re-save nuxt.config.ts and then it restarts, and after a couple of times it (4-5 times it starts working again).

When I have more time, I can see if I can find the exact cause of it myself. But my guess is that it is some kind of race condition.

For now here is some information dump (In the last restart it worked):

    ✔ Nitro built in 965 ms
[nitro] [dev] [uncaughtException] Error: listen EADDRINUSE: address already in use /tmp/nitro/worker-32-1.sock
    at Server.setupListenHandle [as _listen2] (node:net:1415:21)
    at listenInCluster (node:net:1480:12)
    at Server.listen (node:net:1579:5)
    at file:///app/.nuxt/dev/index.mjs:548:8
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '/tmp/nitro/worker-32-1.sock',
  port: -1
}

 ERROR  [worker reload] [worker] exited

  at Worker.<anonymous> (node_modules/nitropack/dist/shared/nitro.e7dc7fe5.mjs:3655:9)
  at Object.onceWrapper (node:events:628:26)
  at Worker.emit (node:events:513:28)
  at Worker.emit (node:domain:489:12)
  at [kOnExit] (node:internal/worker:279:10)
  at Worker.<computed>.onexit (node:internal/worker:199:20)

ℹ Vite client warmed up in 29861ms
ℹ nuxt.config.ts updated. Restarting nuxt...
ℹ Vite client warmed up in 20739ms
✔ Nitro built in 532 ms
Nuxi 3.1.2

  > Local:    http://localhost:3000/ 
  > Network:  http://172.20.0.2:3000/

[nitro] [dev] [uncaughtException] Error: listen EADDRINUSE: address already in use /tmp/nitro/worker-32-2.sock
    at Server.setupListenHandle [as _listen2] (node:net:1415:21)
    at listenInCluster (node:net:1480:12)
    at Server.listen (node:net:1579:5)
    at file:///app/.nuxt/dev/index.mjs:548:8
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '/tmp/nitro/worker-32-2.sock',
  port: -1
}

 ERROR  [worker reload] [worker] exited

  at Worker.<anonymous> (node_modules/nitropack/dist/shared/nitro.e7dc7fe5.mjs:3655:9)
  at Object.onceWrapper (node:events:628:26)
  at Worker.emit (node:events:513:28)
  at Worker.emit (node:domain:489:12)
  at [kOnExit] (node:internal/worker:279:10)
  at Worker.<computed>.onexit (node:internal/worker:199:20)

ℹ nuxt.config.ts updated. Restarting nuxt...
ℹ Vite client warmed up in 18022ms
✔ Nitro built in 488 ms
Nuxi 3.1.2

  > Local:    http://localhost:3000/ 
  > Network:  http://172.20.0.2:3000/

[nitro] [dev] [uncaughtException] Error: listen EADDRINUSE: address already in use /tmp/nitro/worker-32-3.sock
    at Server.setupListenHandle [as _listen2] (node:net:1415:21)
    at listenInCluster (node:net:1480:12)
    at Server.listen (node:net:1579:5)
    at file:///app/.nuxt/dev/index.mjs:548:8
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '/tmp/nitro/worker-32-3.sock',
  port: -1
}

 ERROR  [worker reload] [worker] exited

  at Worker.<anonymous> (node_modules/nitropack/dist/shared/nitro.e7dc7fe5.mjs:3655:9)
  at Object.onceWrapper (node:events:628:26)
  at Worker.emit (node:events:513:28)
  at Worker.emit (node:domain:489:12)
  at [kOnExit] (node:internal/worker:279:10)
  at Worker.<computed>.onexit (node:internal/worker:199:20)

ℹ nuxt.config.ts updated. Restarting nuxt...
ℹ Vite client warmed up in 18264ms
✔ Nitro built in 497 ms
Nuxi 3.1.2

  > Local:    http://localhost:3000/ 
  > Network:  http://172.20.0.2:3000/

[nitro] [dev] [uncaughtException] Error: listen EADDRINUSE: address already in use /tmp/nitro/worker-32-4.sock
    at Server.setupListenHandle [as _listen2] (node:net:1415:21)
    at listenInCluster (node:net:1480:12)
    at Server.listen (node:net:1579:5)
    at file:///app/.nuxt/dev/index.mjs:548:8
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:541:24)
    at async loadESM (node:internal/process/esm_loader:91:5)
    at async handleMainPromise (node:internal/modules/run_main:65:12) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '/tmp/nitro/worker-32-4.sock',
  port: -1
}

 ERROR  [worker reload] [worker] exited

  at Worker.<anonymous> (node_modules/nitropack/dist/shared/nitro.e7dc7fe5.mjs:3655:9)
  at Object.onceWrapper (node:events:628:26)
  at Worker.emit (node:events:513:28)
  at Worker.emit (node:domain:489:12)
  at [kOnExit] (node:internal/worker:279:10)
  at Worker.<computed>.onexit (node:internal/worker:199:20)

ℹ nuxt.config.ts updated. Restarting nuxt...
ℹ Vite client warmed up in 17464ms
✔ Nitro built in 445 ms
Nuxi 3.1.2

  > Local:    http://localhost:3000/ 
  > Network:  http://172.20.0.2:3000/

(node:32) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)

FrozenSteel avatar Feb 06 '23 09:02 FrozenSteel

I put together a sample Nuxt 3 project repo with Docker support + resolving this bug https://github.com/misaon/nuxt-docker.

misaon avatar Mar 03 '23 11:03 misaon

Same problem. It's like nitro do not recive stop signal from docker and do not clean up its stuff.

My minimal representation:

structure image

docker-compose.yml

version: "3.8"

services:
  nuxt:
    container_name: nuxt
    build:
      context: .
      dockerfile: ./docker/nuxt.Dockerfile
    ports:
      - 3000:3000

nuxt.Dockerfile

FROM node:18.16.0

RUN apt-get update

WORKDIR /nuxt
COPY ./nuxt .

RUN npm ci
ENTRYPOINT [ "npm", "run", "dev" ]

wokalek avatar Apr 30 '23 15:04 wokalek

Found out problem.

You need to add volumes:

image

wokalek avatar Apr 30 '23 16:04 wokalek

I am getting this issue without any docker or container usage, just a straightforward pnpm or yarn project.

https://github.com/nuxt/nuxt/issues/21325

EDIT: resolved by killing old stale node processes on my machine.

samijaber avatar Jun 02 '23 15:06 samijaber

Getting the same issue with docker and Nitro 2.6.0 and Nuxt 3.6.5. Cannot docker compose up to simply run the docker container and project only starts after running docker compose up --force-recreate. Hotsaving frontend code doesnt seem to get updated either. Need to run --force-recreate again before the changes are visible on the localhost. Tried many answers in both threads about this issue but I cannot seem to get it resolved.

NickBikker avatar Aug 24 '23 07:08 NickBikker

I am getting this issue without any docker or container usage, just a straightforward pnpm or yarn project.

nuxt/nuxt#21325

EDIT: resolved by killing old stale node processes on my machine.

thank you , i use 'killall node' and it works fine

sonsoixam avatar Oct 01 '23 18:10 sonsoixam

This is still an issue.

nuxt 3.11.2 and just one dependency, @nuxt/ui

Dockerfile:

FROM node:20-alpine

USER node
WORKDIR /home/node
CMD yarn dev

Fixed with

tmpfs:
  - /tmp

in docker-compose as commented in https://github.com/nuxt/nuxt/issues/13587#issuecomment-1451481510

Pijuli avatar May 30 '24 09:05 Pijuli

I have messed around with this a little bit. I ran in to the issue since Im setting up my both my prod and dev environment and I want to be able to run them at the same time. All I had to change was running them on different ports, prod on 3000 and mapped to 8080 while dev is on 3001 and mapped to 3000.

Could be that when Nitro runs in the docker container and another container has the 3000 port mapped it triggers this error, even if its not turned on.

felixrydberg avatar Sep 27 '24 07:09 felixrydberg

This is still an issue.

nuxt 3.11.2 and just one dependency, @nuxt/ui

Dockerfile:

FROM node:20-alpine

USER node
WORKDIR /home/node
CMD yarn dev

Fixed with

tmpfs:
  - /tmp

in docker-compose as commented in nuxt/nuxt#13587 (comment)

We have been using this solution (tmpfs) for a while and it's working as expected. But now we are migrating Yarn Classic (v1) to Berry (v4) and this config causes package.json scripts to fail with permission denied. By the error message it doesn't seem related, but on a fresh Nuxt install, Yarn v4 with node-modules only works without tmpfs config.

andresilva-cc avatar Jan 06 '25 21:01 andresilva-cc