admin管理员组文章数量:1316516
function createSasTokenTimer() {
console.log("Hello");
}
setInterval(createSasTokenTimer, 3000000);
I run this code and after 50 minutes I get the following error:
Hello
timers.js:265
callback.apply(this, args);
^
TypeError: Cannot read property 'apply' of undefined
at wrapper [as _onTimeout] (timers.js:265:13)
at Timer.listOnTimeout (timers.js:110:15)
When the interval time is shorter (2000000 for example), everything works fine.
Is this a bug in Node.js?
Update:
OS: Windows
, Node.js version: 0.12.4
When I run only the code above it works fine, but it does break when it's inside my application, I can't point to which part of my code breaks it as it's very lengthy and nothing looks "suspicious". Anyway, when the interval is shorter it works as I wrote.
function createSasTokenTimer() {
console.log("Hello");
}
setInterval(createSasTokenTimer, 3000000);
I run this code and after 50 minutes I get the following error:
Hello
timers.js:265
callback.apply(this, args);
^
TypeError: Cannot read property 'apply' of undefined
at wrapper [as _onTimeout] (timers.js:265:13)
at Timer.listOnTimeout (timers.js:110:15)
When the interval time is shorter (2000000 for example), everything works fine.
Is this a bug in Node.js?
Update:
OS: Windows
, Node.js version: 0.12.4
When I run only the code above it works fine, but it does break when it's inside my application, I can't point to which part of my code breaks it as it's very lengthy and nothing looks "suspicious". Anyway, when the interval is shorter it works as I wrote.
Share Improve this question edited Jul 23, 2015 at 21:34 bryanmac 39.3k10 gold badges92 silver badges99 bronze badges asked Jul 15, 2015 at 7:37 janivjaniv 7492 gold badges6 silver badges16 bronze badges 19- looks like TaskQueue is invalidating the callback after certain amount of time. I will e try to get the proof to claim assumption and will write an answer to it. BTW nice observation. – Gaurav Gupta Commented Jul 15, 2015 at 8:11
- 2 @janiv Is this the only code running? – Tasos Vogiatzoglou Commented Jul 17, 2015 at 10:01
- 1 @janiv I've tested the code, and it seems to work. Is this the only thing running? Like, is there a possibility for the function to be undefined ? – Tasos Vogiatzoglou Commented Jul 19, 2015 at 10:20
- 2 It looks like a bug in interaction between native C++ binding and V8 garbage collector. This should be easily fixed by keeping object returned by setInterval. I'm digging in. – Ginden Commented Jul 21, 2015 at 12:30
- 2 Node.js implementation of setTimeout and setInterval returns an object. Browsers return an integer. – Ginden Commented Jul 21, 2015 at 17:40
2 Answers
Reset to default 1 +100Instead of calling the Function Directly give it inside a callback.
function createSasTokenTimer() {
console.log("Hello");
}
setInterval(function(){
createSasTokenTimer();
}, 3000000);
Using this method, you are passing an anonymous function to setInterval. It will call this function once per interval, which is 3000000 miliseconds in this example.
For now, you can probably just use this code. For further understanding, I suggest researching anonymous functions and closures.
Hope this helps.
To me this looks like a non standard modual that you are using instead of the native modual. Look at global.process.moduleLoadList
it should have the entries
'NativeModule timers',
'Binding timer_wrap',
And check your code that you are not importing 3rd party timers.js
本文标签: javascriptNodejs crashes when using long interval in setintervalStack Overflow
版权声明:本文标题:javascript - Node.js crashes when using long interval in setinterval - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742007629a2412280.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论