Skip to content

[SSR] Controllers are not garbage collected correctly #778

@RafalFilipek

Description

@RafalFilipek

Bug report

Describe the bug

Hi,

I found this bug in my Next.js app, but we think it's not related to NextJS itself but rather SSR in general.

Let's go straight to example:

To Reproduce

This command will start production version of application with --inspect flag to enable NodeJs debugger.

  • open [http://localhost:3000](http://localhost:3000) in Chome
  • open DevTools and click NodeJS logo on the left

Screenshot 2019-08-02 at 16 29 46

This will open Dedicated NodeJS debugger.

  • open Memory tab, select Heap Snapshot and click Take Snapshot. You will get something like this:

Screenshot 2019-08-02 at 16 31 37

Now it's time to make some requests. I'm using autocannon, but you can use any tool like ab.

autocannon -c 50 -a 1000 http://localhost:3000 

Now you can take second snapshot. It should be much bigger:

Screenshot 2019-08-02 at 16 35 21

After 4K requests you will see that there is a lot of allocations in array part. For some reason there are many allocations of Controller class from react-spring. I have no idea why.

Screenshot 2019-08-02 at 16 42 20

It looks like new Controller class is created for each request, but old instances are not garbage collected. (this and this lines?)

Now let's compare snapshots in this same application but without getInitialProps in _app.js - no SRR.

After 10K request you will get something like this:

Screenshot 2019-08-02 at 16 48 22

  • Snapshot 1 - after yarn start
  • Snapshot 2 - after 10K req
  • Snapshot 3 - after GC

System information

  • OS: macOs / Docker 12.4.0-alpine
  • Version of Next.js: 9.0.2, 9.0.3
  • Version of react-spring 8.0.27, 9.0.0-beta.31
  • Version of React: 16.8.6

Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions