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

ERR_INVALID_ARG_TYPE when closing app #55631

Closed
1 task done
MariuzM opened this issue Sep 20, 2023 · 12 comments
Closed
1 task done

ERR_INVALID_ARG_TYPE when closing app #55631

MariuzM opened this issue Sep 20, 2023 · 12 comments
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@MariuzM
Copy link

MariuzM commented Sep 20, 2023

Link to the code that reproduces this issue

https://github.com/MariuzM/test_next

To Reproduce

When i do CTRL + C to close app i get this error, this started happening with 13.5.1

▲ Next.js 13.5.1
  - Local:        http://localhost:3000
  - Experiments (use at your own risk):
     · externalDir

 ✓ Ready in 748ms
^CTypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.cleanup (/Users/marius/Desktop/test_next/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:208:29)
    at process.emit (node:events:526:35) {
  code: 'ERR_INVALID_ARG_TYPE'
}
TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.cleanup (/Users/marius/Desktop/test_next/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:208:29)
    at process.emit (node:events:526:35) {
  code: 'ERR_INVALID_ARG_TYPE'
}

 X uncaughtException: TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.cleanup (/Users/marius/Desktop/test_next/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:208:29)
    at process.emit (node:events:526:35) {
  code: 'ERR_INVALID_ARG_TYPE'
}
 X uncaughtException: TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.cleanup (/Users/marius/Desktop/test_next/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:208:29)
    at process.emit (node:events:526:35) {
  code: 'ERR_INVALID_ARG_TYPE'
}
TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.cleanup (/Users/marius/Desktop/test_next/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:208:29)
    at process.emit (node:events:526:35) {
  code: 'ERR_INVALID_ARG_TYPE'
}
TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.cleanup (/Users/marius/Desktop/test_next/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:208:29)
    at process.emit (node:events:526:35) {
  code: 'ERR_INVALID_ARG_TYPE'
}
 X uncaughtException: TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.cleanup (/Users/marius/Desktop/test_next/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:208:29)
    at process.emit (node:events:526:35) {
  code: 'ERR_INVALID_ARG_TYPE'
}
 X uncaughtException: TypeError [ERR_INVALID_ARG_TYPE]: The "code" argument must be of type number. Received type string ('SIGINT')
    at process.set [as exitCode] (node:internal/bootstrap/node:123:9)
    at process.exit (node:internal/process/per_thread:188:24)
    at process.cleanup (/Users/marius/Desktop/test_next/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/next/dist/server/lib/start-server.js:208:29)
    at process.emit (node:events:526:35) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Current vs. Expected behavior

No errors

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      Version: Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000
    Binaries:
      Node: 20.6.1
      npm: 9.8.1
      Yarn: 1.22.19
      pnpm: 8.6.12
    Relevant Packages:
      next: 13.5.1
      eslint-config-next: 13.5.1
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.2.2
    Next.js Config:
      output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

No response

NEXT-1640

@MariuzM MariuzM added the bug Issue was opened via the bug report template. label Sep 20, 2023
@ab70
Copy link

ab70 commented Sep 20, 2023

Along with that, I tried canary and latest release. After stopping server by CTL + C , it actually didnt stop the server, in background i can see the server is still running, and if i save any file after changing in that repo, it automatically starts again, although i just stopped server. Now i need to kill the process. Earlier in dev mode memory usage going high, still its going high, but after restarting server provides some relief for a while,
and now after even stopping i need to kill that process manually!

@joulev
Copy link
Contributor

joulev commented Sep 20, 2023

At least the ERR_INVALID_ARG_TYPE error is fixed in #55606. Wait for the next canary release.

@joulev
Copy link
Contributor

joulev commented Sep 20, 2023

I can confirm that #55606 indeed resolved this. The error is gone, the next-router-worker is also terminated correctly too.

image

While we wait for a canary release, you can use pnpm-patch if you use pnpm with this patch file

diff --git a/dist/server/lib/start-server.js b/dist/server/lib/start-server.js
index fb221537008462774227e0567cbc7087455e8a87..c637e54f789d757bb28a8da4c74072b7957122ba 100644
--- a/dist/server/lib/start-server.js
+++ b/dist/server/lib/start-server.js
@@ -211,9 +211,10 @@ async function startServer({ dir, port, isDev, hostname, minimalMode, allowRetry
                     // This is the render worker, we keep the process alive
                     console.error(err);
                 };
-                process.on("exit", cleanup);
-                process.on("SIGINT", cleanup);
-                process.on("SIGTERM", cleanup);
+                process.on('exit', (code) => cleanup(code))
+                // callback value is signal string, exit with 0
+                process.on('SIGINT', () => cleanup(0))
+                process.on('SIGTERM', () => cleanup(0))
                 process.on("uncaughtException", exception);
                 process.on("unhandledRejection", exception);
                 const initResult = await getRequestHandlers({

If you use something other than pnpm, look for solutions to patch packages.

@MariuzM
Copy link
Author

MariuzM commented Sep 20, 2023

I can confirm that #55606 indeed resolved this. The error is gone, the next-router-worker is also terminated correctly too.
image

While we wait for a canary release, you can use pnpm-patch if you use pnpm with this patch file

diff --git a/dist/server/lib/start-server.js b/dist/server/lib/start-server.js
index fb221537008462774227e0567cbc7087455e8a87..c637e54f789d757bb28a8da4c74072b7957122ba 100644
--- a/dist/server/lib/start-server.js
+++ b/dist/server/lib/start-server.js
@@ -211,9 +211,10 @@ async function startServer({ dir, port, isDev, hostname, minimalMode, allowRetry
                     // This is the render worker, we keep the process alive
                     console.error(err);
                 };
-                process.on("exit", cleanup);
-                process.on("SIGINT", cleanup);
-                process.on("SIGTERM", cleanup);
+                process.on('exit', (code) => cleanup(code))
+                // callback value is signal string, exit with 0
+                process.on('SIGINT', () => cleanup(0))
+                process.on('SIGTERM', () => cleanup(0))
                 process.on("uncaughtException", exception);
                 process.on("unhandledRejection", exception);
                 const initResult = await getRequestHandlers({

If you use something other than pnpm, look for solutions to patch packages.

off topic, i love your terminal. what theme is that?

@joulev
Copy link
Contributor

joulev commented Sep 20, 2023

Monokai Pro on VSCode.

@MariuzM
Copy link
Author

MariuzM commented Sep 20, 2023

I'm also noticing maybe memory leak? each time i save the ram gets more and more for next-router-worker it does clean up but not as low as initially started, but it just keeps increasing again and again, and now my hello world app is like 1gb vs 100mb when i started

@azvyae
Copy link

azvyae commented Sep 20, 2023

@MariuzM yes it is, so this is related then #55649

@MariuzM
Copy link
Author

MariuzM commented Sep 20, 2023

@azvyae understand about duplication, but when using with single one and you keep saving lets say a .tsx file you will notice that ram keeps increasing for that next-router-worker instance.

@MariuzM
Copy link
Author

MariuzM commented Sep 20, 2023

Screen.Recording.2023-09-20.at.17.06.05.mov

@MariuzM
Copy link
Author

MariuzM commented Sep 20, 2023

Garbage collector kicks in but it not as low as it should be but even with GC it keeps increasing the more i save

@balazsorban44 balazsorban44 added the linear: next Confirmed issue that is tracked by the Next.js team. label Sep 20, 2023
@balazsorban44
Copy link
Member

This has been fixed on the latest next@canary, please try it out!

You have to be at least on: 13.5.2-canary.0

@github-actions
Copy link
Contributor

github-actions bot commented Oct 4, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Oct 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
Development

No branches or pull requests

5 participants