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

RangeError: Maximum call stack size exceeded #113

Open
relisiuol opened this issue Feb 22, 2020 · 2 comments
Open

RangeError: Maximum call stack size exceeded #113

relisiuol opened this issue Feb 22, 2020 · 2 comments

Comments

@relisiuol
Copy link

relisiuol commented Feb 22, 2020

Hello,

I tried to use this library to optimize a website speed, that worked great but sometimes a crash occurs. If you can help, that would be nice.

Log:

[22/Feb/2020:10:03:18 +0100] [upstream] Upstream started PID: 1163837
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR: internal/timers.js:279
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR: function incRefCount() {
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:                     ^
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR: 
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR: RangeError: Maximum call stack size exceeded
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at incRefCount (internal/timers.js:279:21)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at insert (internal/timers.js:336:7)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at active (internal/timers.js:292:3)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at setTimeout (timers.js:143:3)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at Cache.put (node_modules/memory-cache/index.js:34:24)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at ServerResponse.res.send [as sendResponse] (app.js:69:16)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at ServerResponse.res.send [as sendResponse] (app.js:70:13)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at ServerResponse.res.send [as sendResponse] (app.js:70:13)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at ServerResponse.res.send [as sendResponse] (app.js:70:13)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] STDERR:     at ServerResponse.res.send [as sendResponse] (app.js:70:13)
[22/Feb/2020:10:15:26 +0100] [upstream] [1163837] Upstream stopped (reason: exited spontaneously with return code 1)

Cache function into app.js

const mcache = require('memory-cache');

var cache = (duration) => {
  return (req, res, next) => {
    let key = '__express__' + req.originalUrl || req.url
    let cachedBody = mcache.get(key)
    if (cachedBody) {
      res.send(cachedBody)
      return
    } else {
      res.sendResponse = res.send
      res.send = (body) => {
        mcache.put(key, body, duration * 1000);
        res.sendResponse(body)
      }
      next()
    }
  }
}

Have a good day'

@emauriciomoreno
Copy link

The problem is not in the library, the error it shows you is an issue in the memory of your server. You are caching or in RAM and add to that the processes that your application is running, until a moment comes when that memory is exhausted and when the garbage collector releases a little of that memory the error disappears. You must be careful because when your application grows or traffic increases, those errors can be more frequent. You should analyze when it is convenient to cache the responses from your server

@IvanAdmaers
Copy link

I can guess it may happen when you cache too many data. Also you should keep it on mind there is a difference between server and your local machine power. For caching a large amount of data you should take a look on redis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants