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

Memory leak when refreshing during rebuild #1428

Closed
nickredmark opened this issue Mar 15, 2017 · 30 comments · Fixed by #4639
Closed

Memory leak when refreshing during rebuild #1428

nickredmark opened this issue Mar 15, 2017 · 30 comments · Fixed by #4639
Labels
please add a complete reproduction Please add a complete reproduction.

Comments

@nickredmark
Copy link

nickredmark commented Mar 15, 2017

Sometimes when I modify a file, and next.js is rebuilding, and then quickly move to the browser and refresh the page, the browser's memory quickly goes up until the computer freezes.

Browser: Firefox 52.0
Next version: [email protected]

@timneutkens
Copy link
Member

Like an infinite loop?

@nickredmark
Copy link
Author

Maybe, but a loop on its own wouldn't cause the browser to fill up the RAM. Interestingly enough it hasn't happened (yet) with chrome.

@arunoda
Copy link
Contributor

arunoda commented Mar 15, 2017

EDIT: It seems like you are using the latest Next version.

@nmaro are you using the latest version of Next.
We recently removed our React patching code and that might a case for this.

@arunoda
Copy link
Contributor

arunoda commented Mar 15, 2017

@nmaro I tried with our Zeit.co and with few other apps. I couldn't reproduce the issue.
May be it's because of one of the NPM module you use or something in your app.

Is it possible for you to isolate that?

@arunoda arunoda added the please add a complete reproduction Please add a complete reproduction. label Mar 15, 2017
@arunoda
Copy link
Contributor

arunoda commented Mar 18, 2017

I'm gonna close this for now. Feel free to re-open with some ways to re-produce this.

@arunoda arunoda closed this as completed Mar 18, 2017
@kunokdev
Copy link

I am using Next.js and sometimes I get infinite loop inside Firefox browser when I open developer tools. Version of Nextjs is 2.4.0 and Firefox 53. Other than that, sometimes when I hard refresh page it tends to rebuild again, and once loaded, it rebuilds again, infinitively.

@pmualaba
Copy link

pmualaba commented Jun 15, 2017

Same issue here: When using next.js with express custom server, and hard refreshing the page in the browser a few times creates an infinite refresh loop in the browser:
i use npm run dev with the following settings:

package.json:
"scripts": {
"dev": "NODE_ENV=development pm2 start node.config.js --no-daemon"
...

node.config.js :
module.exports = {
apps: [{
name: 'server',
script: './server.js',
instances: 1,
exec_mode: 'cluster',
watch: ['packages/**/api/*'],
ignore_watch: ['node_modules', '.temp', '.next', '.git']
}]
}

@kunokdev
Copy link

kunokdev commented Jul 14, 2017

Can this issue be reopened? I had to completely move to Chrome in order to develop in Next.js. Anytime I try to open my project (dev mode only) in Firefox I get instant memory overload and must force reset. I never had any issues with Firefox before. Could we start examining the cause of this problem? I will try to explore what caused this issue to reproduce it.

@Angel200O
Copy link

Angel200O commented Jul 14, 2017

I had to completely move to Chrome in order to develop in Next.js. Anytime I try to open my project (dev mode only) in Firefox I get instant memory overload and must force reset.

This has been happening to me but i can't remember on which version the problem started or if it hasnt been there since i started using Next on January

@arunoda
Copy link
Contributor

arunoda commented Jul 15, 2017

Let's investigate this further.

@arunoda arunoda reopened this Jul 15, 2017
@nathanqueija
Copy link

nathanqueija commented Jul 20, 2017

Same happening here:
`<--- Last few GCs --->

1716321 ms: Mark-sweep 1358.7 (1406.0) -> 1366.3 (1407.0) MB, 453.3 / 0.0 ms [allocation failure] [GC in old space requested].
1716762 ms: Mark-sweep 1366.3 (1407.0) -> 1366.2 (1397.0) MB, 441.4 / 0.0 ms [allocation failure] [GC in old space requested].
1717163 ms: Mark-sweep 1366.2 (1397.0) -> 1366.1 (1397.0) MB, 400.5 / 0.0 ms [last resort gc].
1717589 ms: Mark-sweep 1366.1 (1397.0) -> 1366.0 (1397.0) MB, 426.4 / 0.1 ms [last resort gc].

<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x3e39fcfcfb39
1: fromString(aka fromString) [buffer.js:~187] [pc=0xdb05e622dae] (this=0x3e39fcf04381 ,string=0x18d918474711 <Very long string[5862787]>,encoding=0x3e39fcfdd071 <String[5]: utf-8>)
2: new constructor(aka Buffer) [buffer.js:~71] [pc=0xdb05d2cb48a] (this=0x18d918474999 <a Buffer with map 0x113f0dd2fcd9>,arg=0x18d918474711 <Very long string[5862787]>,encodingOrOffset=0x3e39fcfd...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::String::SlowFlatten(v8::internal::Handlev8::internal::ConsString, v8::internal::PretenureFlag) [/usr/local/bin/node]
6: v8::String::WriteUtf8(char*, int, int*, int) const [/usr/local/bin/node]
7: node::StringBytes::Write(v8::Isolate*, char*, unsigned long, v8::Localv8::Value, node::encoding, int*) [/usr/local/bin/node]
8: node::Buffer::New(v8::Isolate*, v8::Localv8::String, node::encoding) [/usr/local/bin/node]
9: node::Buffer::CreateFromString(v8::FunctionCallbackInfov8::Value const&) [/usr/local/bin/node]
10: 0xdb05e0edc38
[1] 73670 abort npm run dev`

@kunokdev
Copy link

kunokdev commented Jul 20, 2017

@nathanqueija do you remember at which point did memory leak appear? Do you use any custom config such as extended .babelrc? Can you share your package.json?

@thangngoc89
Copy link

I'm experiencing too often that this become to bother me.

Here is the dump

<--- Last few GCs --->                
     
[16570:0x340a5a0] 10373222 ms: Mark-sweep 1387.6 (1469.8) -> 1387.5 (1469.3) MB, 641.4 / 0.1 ms  allocation failure GC in old space requested
[16570:0x340a5a0] 10374158 ms: Mark-sweep 1387.5 (1469.3) -> 1387.2 (1427.8) MB, 936.1 / 0.2 ms  last resort
[16570:0x340a5a0] 10374768 ms: Mark-sweep 1387.2 (1427.8) -> 1387.1 (1427.8) MB, 610.0 / 0.1 ms  last resort
                                                                     
                                                                     
<--- JS stacktrace --->                                              
       
==== JS stack trace =========================================        
                                                                     
Security context: 0x3813d7929891 <JS Object>   
    1: DoJoin(aka DoJoin) [native array.js:~96] [pc=0x247d5ddf6c85](this=0x18c20aa82311 <undefined>,p=0x3dab2e9ad69 <JS Array[2]>,q=2,E=0x18c20
aa823b1 <true>,A=0x18c20aa82471 <String[0]: >,z=0x18c20aa82421 <false>)
    2: Join(aka Join) [native array.js:~121] [pc=0x247d5d62cfa8](this=0x18c20aa82311 <undefined>,p=0x3dab2e9ad69 <JS Array[2]>,q=2,A=0x18c20aa8
2471 <String[0]: >,z=0x18c20aa82421 <fa...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out ofmemory
 1: node::Abort() [node]
 2: 0x13647ec [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::Runtime_StringBuilderConcat(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 7: 0x247d5830437d
Aborted (core dumped)
error Command failed with exit code 134.

It usually happens every 1-2 hours in development mode. I know that tracing a memory leak is hard but any pointer where should I start to kill this bug would be appreciated

@nickredmark
Copy link
Author

As the op wanted to say that this is still happening to me, basically gave up on developing with firefox altogether. With chrome everything works fine for me.

@thangngoc89
Copy link

@nmaro oh so this issue is about memory leak in the browser? My issue is with the node process, and it happens no matter which browser I use (I develop on Chrome, Firefox)

@nickredmark
Copy link
Author

At least my issue, yes. I have to kill the browser in time or it blocks everything and have to restart my pc :)

@timneutkens
Copy link
Member

I wonder if this might be related to a memory leak we fixed before related to calling /static/ in your browser.

@kunokdev
Copy link

kunokdev commented Aug 7, 2017

@timneutkens can you link to that issue related to ./static dir?
@nmaro @thangngoc89 do you use custom .babelrc file? can you share your package.JSON? are you using nodemon ? also, how did you wrap your components that live inside ./pages directory?

@TAQ2
Copy link

TAQ2 commented Aug 7, 2017

I would also check what version of node you are on. That seemed to fix this exact issue for me. I moved from version 6 to 8

@kunokdev
Copy link

kunokdev commented Aug 7, 2017

@TAQ2 just tried upgrading from 6 to 8 and memory leak is still present. Had to kill it before it fills my RAM completely and forces me to reboot by force. I tried few times to find issue but I couldn't because project is too big, so I am trying to see what others have enabled to build reproductive example. I also want to mention that leak is happening at the browser, not build process in my case

image

@nickredmark
Copy link
Author

It happens in a number of projects, in my current one I'm not using .babelrc. No nodemon. Here's my package.json: https://github.com/nmaro/sorters/blob/master/package.json

@ebrearley
Copy link

This happened to me a few hours ago. I was utterly baffled cause I was only making superficial changes. Anyway, for me the problem was caused by accidentally thumbing the keyboard and creating a copy of node_modules in the /pages directory. No wonder the call stack overflowed.

I deleted the accidental rogue node_modules directory, back to normal.

@DaniellaGiovanna
Copy link

I just started trying out Next.js and the same thing is happening (Chrome as well as Firefox). I started in a clean directory, ran npm install --save react react-dom next and added a page ./pages/index.js and a very basic component ./components/intro.js. Both don't do anything special. The first includes the latter.

It happened after a couple of hours and several manual refreshes as well as restarts of the server as I was fiddling around with things, going through the docs and such. Not a single extra dependency was installed, no additional babel/webpack configs were made during the life of the project.

See this gist for the complete life of the project, from inception to errors.

@geryit
Copy link

geryit commented Jan 3, 2018

Same problem here with chrome and firefox:

.babelrc:

{
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  },
  "plugins": [
    "transform-decorators-legacy"
  ],
  "presets": [
    "next/babel",
    "stage-0"
  ],
  "ignore": []
}

package.json:

"scripts": {
    "dev": "nodemon server.js --watch server.js --watch next.config.js  --watch package.json"
}

@nickredmark
Copy link
Author

nickredmark commented Jan 4, 2018

Interestingly, this stopped happening for me with the newest firefox/next.

@flybayer
Copy link
Contributor

Firefox 60 has become completely unusable for Next development on this project: https://github.com/beedesignllc/glutenproject.com, especially the store branch.

It's not long after loading the page and/or changes that Firefox gets super sluggish, requiring a Firefox restart.

But Chrome works great.

@kunokdev
Copy link

@nmaro Same here

@timneutkens
Copy link
Member

I hope this is fixed by #4639, not entirely sure as I couldn't reproduce.

@devhyunjae
Copy link

I think this is the same issue
#5421

@lock lock bot locked as resolved and limited conversation to collaborators Oct 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
please add a complete reproduction Please add a complete reproduction.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

15 participants