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

Running node-cluster preset build throwing EADDRINUSE errors #2892

Closed
aisteneciunaitevalantic opened this issue Nov 19, 2024 · 5 comments · Fixed by #2894
Closed

Running node-cluster preset build throwing EADDRINUSE errors #2892

aisteneciunaitevalantic opened this issue Nov 19, 2024 · 5 comments · Fixed by #2894
Labels
bug Something isn't working preset:node-cluster

Comments

@aisteneciunaitevalantic
Copy link

aisteneciunaitevalantic commented Nov 19, 2024

Environment

Node Version: v18.20.3
Nitro Version: 2.10.4

Reproduction

https://stackblitz.com/edit/github-mrhh35?file=nitro.config.ts

> npm run build
> npm run preview

Describe the bug

Running application with preset 'node-cluster' is throwing EADDRINUSE errors

Additional context

No such issue in v2.9.7

Logs

[nitro] [uncaughtException] Error: bind EADDRINUSE null:3000
    at __node_internal_captureLargerStackTrace2 (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:101:5335)
    at __node_internal_exceptionWithHostPort2 (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:101:7017)
    at listenOnPrimaryHandle (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:285:12098)
    at rr (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:55:2291)
    at Worker.<anonymous> (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:55:2716)
    at _0x54dcec.onInternalMessage (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:59:458)
    at _0x54dcec.emit (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:30:11015)
    at emit (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:52:6956)
    at processTicksAndRejections (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:192:1093)
    at https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/blitz.d3acb9e1.js:40:198427
    at _0x40724c (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/blitz.d3acb9e1.js:40:198508)
    at _0x323f12 (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/blitz.d3acb9e1.js:40:508059)
    at https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/blitz.d3acb9e1.js:40:508836
    at Array.forEach (<anonymous>)
    at _0x325fd3 (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/blitz.d3acb9e1.js:40:508824)
    at Map.forEach (<anonymous>)
    at _0x26b4f2 (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/blitz.d3acb9e1.js:40:508453)
    at _0x2934c6 (https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/blitz.d3acb9e1.js:40:507451)
    at https://qgnirvpgrqgithub-iuqv.w-credentialless-staticblitz.com/blitz.d3acb9e1.js:40:507618 {
  errno: -48,
  code: 'EADDRINUSE',
  syscall: 'bind',
  address: null,
  port: 3000
}
@OskarLebuda
Copy link

Probably, the problem lies here:
https://github.com/nitrojs/nitro/blob/v2/src/presets/node/runtime/node-server.ts#L32

The code with server should be exported as a main (or similarly named) function.
After a simple change to node-server.ts:

export const main = async () => {
  // all code here
};

Then, node-cluster.ts should update the import in the runWorker function:

function runWorker() {
  import("./node-server")
    .then((server) => {
      server.main();
    })
    .catch((error) => {
      console.error(error);
      process.exit(1);
    });
}

Result:
image

I've created a PR for this fix: #2893

@pi0
Copy link
Member

pi0 commented Nov 19, 2024

Thanks for the report. this issue should be fixed in the nightly channel.

@Zae
Copy link

Zae commented Nov 21, 2024

Any idea when we can expect this fix in nuxt stable? Right now node_cluster mode is totally broken in nuxt > 3.13

@pi0
Copy link
Member

pi0 commented Nov 21, 2024

You can pin nitropack only to latest nightly build with Nuxt.

@Zae
Copy link

Zae commented Dec 24, 2024

Hi @pi0 , using the nightly build is not really a fix for us in production, is there a way to get this fix into stable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preset:node-cluster
Projects
None yet
4 participants