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

worker: listen EADDRINUSE: address already in use #885

Open
pi0 opened this issue Jan 26, 2023 · 12 comments
Open

worker: listen EADDRINUSE: address already in use #885

pi0 opened this issue Jan 26, 2023 · 12 comments

Comments

@pi0
Copy link
Member

pi0 commented Jan 26, 2023

Context: nuxt/nuxt#13587

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

@misaon
Copy link

misaon commented Jan 26, 2023

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

@Intevel
Copy link
Contributor

Intevel commented Jan 26, 2023

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.

@FrozenSteel
Copy link

FrozenSteel commented Feb 6, 2023

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)

@misaon
Copy link

misaon commented Mar 3, 2023

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

@wokalek
Copy link

wokalek commented Apr 30, 2023

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
Copy link

wokalek commented Apr 30, 2023

Found out problem.

You need to add volumes:

image

@samijaber
Copy link

samijaber commented Jun 2, 2023

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.

@NickBikker
Copy link

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.

@sonsoixam
Copy link

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

Shard added a commit to userback/widget-js that referenced this issue Oct 4, 2023
Ensure nitro doesn't leave stale worker sockets before attempting to serve.

nitrojs/nitro#885

Also update config inline with current v3 docs
Shard added a commit to userback/widget-js that referenced this issue Oct 4, 2023
Ensure nitro doesn't leave stale worker sockets before attempting to serve.

nitrojs/nitro#885

Also update config inline with current v3 docs
Shard added a commit to userback/widget-js that referenced this issue Oct 4, 2023
* Fix incorrect readme example

* Upgrade minor packages

Ensure host is set to 0.0.0.0

* Fix nuxt nitro issues

Ensure nitro doesn't leave stale worker sockets before attempting to serve.

nitrojs/nitro#885

Also update config inline with current v3 docs

* Update depepdency review

Use v3 and only fail on high and critical severity CVE's.

* Update to node18

* Improve reliability of the modal selector

`.userback-controls` is always present, no matter the user configuration.
@Pijuli
Copy link

Pijuli commented May 30, 2024

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)

@felixrydberg
Copy link

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.

@andresilva-cc
Copy link

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.

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