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

Recursive call: RangeError: Maximum call stack size exceeded when deleteOnExpire:false #313

Open
raxitsheth opened this issue Sep 6, 2023 · 0 comments

Comments

@raxitsheth
Copy link

Hi

This is a specific case when deleteOnExpire:false and try to use has/get function in .on("expired", (key,value) => callback)

Here is a small sample code to test the behaviour

import NodeCache from 'node-cache';

const myCache = new NodeCache({checkperiod:10,deleteOnExpire:false});
myCache.on( "set", ( key, value ) => console.log("On SET "+ key + '=' + value));
myCache.on( "del", ( key, value ) => console.log("On DEL: "+ key + '=' + value));
myCache.on( "expired", ( key, value ) => {
        console.log("On EXPIRED "+ key + '=' + value);
        //myCache.set(key, value+'_',10); // <-- Uncommenting will work, commenting this line will crash process due to either of below lines causing recursion 
        let test1 = myCache.has(key); //<--
        let test2 =myCache.get(key); // <-- 
});

myCache.set("MyKey","MyValue",5);

//Below code is dummy/sample long running code.... 
let done =1;
(function wait () {
   if (done) setTimeout(wait, 1000);
})();

─$ node test.mjs
On EXPIRED MyKey=MyValue
On EXPIRED MyKey=MyValue
On EXPIRED MyKey=MyValue
....
On EXPIRED MyKey=MyValue
node:internal/console/constructor:309
if (isStackOverflowError(e))
^

RangeError: Maximum call stack size exceeded
at console.value (node:internal/console/constructor:309:13)
at console.log (node:internal/console/constructor:380:26)
at NodeCache. (file:///Users/raxitsmacbook/MyNodeRnd/test.mjs:7:10)
at NodeCache.emit (node:events:514:28)
at NodeCache._check (/Users/raxitsmacbook/MyNodeRnd/node_modules/node-cache/lib/node_cache.js:659:16)
at NodeCache.has (/Users/raxitsmacbook/MyNodeRnd/node_modules/node-cache/lib/node_cache.js:575:52)
at NodeCache. (file:///Users/raxitsmacbook/MyNodeRnd/test.mjs:9:22)
at NodeCache.emit (node:events:514:28)
at NodeCache._check (/Users/raxitsmacbook/MyNodeRnd/node_modules/node-cache/lib/node_cache.js:659:16)
at NodeCache.has (/Users/raxitsmacbook/MyNodeRnd/node_modules/node-cache/lib/node_cache.js:575:52)

Node.js v18.17.1 (However it looks like this behaviour is independent of Node version, Just in case if version can be of any help.)

Possible bug also in: mget when deleteOnExpire:false

Also when deleteOnExpire:false it constantly emits "expired" event on every 'checkperiod' times. (But it does not crash, But nice to have non-periodic expire event unless the object/key/value/expiry etc has been modified.

@raxitsheth raxitsheth changed the title Recursive call: RangeError: Maximum call stack size exceeded - deleteOnExpire:false Recursive call: RangeError: Maximum call stack size exceeded when deleteOnExpire:false Sep 6, 2023
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

1 participant