Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Maximum call stack size exceeded #5

Open
gilly3 opened this issue Jun 3, 2016 · 5 comments
Open

Maximum call stack size exceeded #5

gilly3 opened this issue Jun 3, 2016 · 5 comments

Comments

@gilly3
Copy link

gilly3 commented Jun 3, 2016

While load testing my app, I am seeing RangeError: Maximum call stack size exceeded, with promise-redis in the stack trace. Asking here is a bit of a stab in the dark, but I thought I'd check. Here are a couple of suspicious looking stack traces:

image

I have to process several thousand requests before I start seeing this error. It looks like the promisify function is calling itself recursively. Any idea what might be causing this?

@gilly3
Copy link
Author

gilly3 commented Jun 16, 2016

FYI: I was able to resolve this by writing my own promise wrapper that has no chance of recursive function calls. I'm no longer using promise-redis and the errors are gone.

@mdjaman
Copy link

mdjaman commented Jun 28, 2016

@gilly3 Can you share your code please

@maxbrieiev
Copy link
Owner

Hi!

Sorry for late reply. promise-redis doesn't do any recursive calls.

What node_redis version is used here? Is it possible to create a reproducible example? If not, could you share parts of code that cause this error.

Thanks.

@gilly3
Copy link
Author

gilly3 commented Jun 28, 2016

I had tried to boil this down to a small example, but was unable to do so. Any attempts at isolating the problem were unable to reproduce the error. Running all of my code, I was only ever able to reproduce this while under extreme load for several minutes.

The stack trace led me to line 35, which is f.apply(this, args) within promisify():

if (typeof args[args.length - 1] === 'function') {
    // Okay. Someone supplied a callback. Most likely some internal
    // node-redis call (ready probe etc.). Oh, as a result of
    // supporting internal callback-style calls, one can now use
    // promise-redis as a dropin replacement for node-redis.
    f.apply(this, args);
}

The recursion could occur if a promisified function is being passed as a parameter, thus being repromisified. My code isn't doing this, as I use promises instead of callbacks. I stopped digging and just wrote my own promisifier for the few redis calls that I need.

I was using only GET, SET, PUBLISH, and SUBSCRIBE commands. I've since abandoned PUBLISH and SUBSCRIBE, so to promisify my calls now, it's something like this:

function get(key) {
    return new Promise((resolve, reject) =>
        client.get(key, (err, data) => err ? reject(err) : resolve(data)));
}
function set(key, val, expire) {
    return new Promise((resolve, reject) =>
        client.set(key, val, "EX", expire, (err, data) => err ? reject(err) : resolve(data)));
}

@maxbrieiev
Copy link
Owner

maxbrieiev commented Jun 28, 2016

Thanks for your reply.

"promisification" happens only once, when promise-redis is initialized. Each redis command is replaced with the function returned from promisify function.

From the stack trace it looks that it is internal_send_command that passes a callback to promisified set command. But it is hard to tell what happens in the originating code, because line 877 from the latest node_redis git repo doesn't point to any function call.

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

No branches or pull requests

3 participants