iaincollins / nextjs-starter

A starter project for Next.js with authentication
https://nextjs-starter.now.sh
ISC License
1.37k stars 422 forks source link

Memory leak in app created from this boilerplate #117

Open dongrh214 opened 4 years ago

dongrh214 commented 4 years ago

Bug report

We have some problem on our server. After some time of execution we have an out of memory error on our server. So I tried to reproduce on my computer. I create a clean project just use nextjs-starter. and build it.run it using pm2, after one three to see if the memory increase. Here is the memory evolution :

b882ca53-727a-4c84-b014-b1e9dbcd9b61

pm2 monit show like this:

64d616e1-1bce-4d22-8311-7c0ef85441a4 6dafeb61-ee62-41c8-af3f-82a3d16eab5c

Describe the bug

you can see the heap size awaly increasing when i use loadtest request

To Reproduce

  1. git clone https://github.com/iaincollins/nextjs-starter
  2. cd nextjs-starter
  3. npm i
  4. add pm2.config.js file

       const pkg = require("./package.json");
    
       module.exports = {
            apps: [
                {
                     name: pkg.name,
                     script: "index.js",
                     instances: 1,
                     exec_mode: "cluster",
                     watch: false,
                     node_args: "--inspect --expose-gc",
                     max_memory_restart: "1500M",
                     env: {
                          NODE_ENV: "development",
                          BUILD_ENV: "test",
                          RUNTIME_ENV: "test",
                     },
                     env_test: {
                          NODE_ENV: "production",
                          BUILD_ENV: "test",
                          RUNTIME_ENV: "test",
                    },
               },
           ],
     };
    1. npm run build
    2. pm2 start pm2.config.js
    3. loadtest -c 30 --rps 20 http://localhost:80
    4. you can use pm2 monit or chrome://inspect See error I also use express test, it is ok!

system information

 OS: macOS
 Version of pm2: 4.2.1
 Version of loadtest: 4.1.0

Additional context

  use pm2 log see node inspect port

ad03283b-19e2-4928-a34c-e942a22162e3 8b6e20b7-6b9a-469d-bc9b-ccca6019f14e