summaryrefslogtreecommitdiff
path: root/jstests/core/recursion.js
diff options
context:
space:
mode:
authorJason Carey <jcarey@argv.me>2015-09-25 15:34:18 -0400
committerJason Carey <jcarey@argv.me>2015-10-06 19:10:55 -0400
commite5f65d77a33e5116adb965549deb51ab3ed0a462 (patch)
tree254d9214f40f5a169dc93c1fde792c8ab02fe26b /jstests/core/recursion.js
parente01a0919ef79781d4beff44dad5ce42e0e9fee15 (diff)
downloadmongo-e5f65d77a33e5116adb965549deb51ab3ed0a462.tar.gz
SERVER-19614 Implement stack quotas for JS
Replace existing calls to std::thread with platform threading primitives and set a stack quota to avoid stack overflows for some recursive use cases in js.
Diffstat (limited to 'jstests/core/recursion.js')
-rw-r--r--jstests/core/recursion.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/jstests/core/recursion.js b/jstests/core/recursion.js
new file mode 100644
index 00000000000..dc7b51be845
--- /dev/null
+++ b/jstests/core/recursion.js
@@ -0,0 +1,41 @@
+// Basic tests for a form of stack recursion that's been shown to cause C++
+// side stack overflows in the past. See SERVER-19614.
+
+(function () {
+ "use strict";
+
+ db.recursion.drop();
+
+ // Make sure the shell doesn't blow up
+ function shellRecursion() {
+ shellRecursion.apply();
+ }
+ assert.throws(shellRecursion);
+
+ // Make sure db.eval doesn't blow up
+ function dbEvalRecursion() {
+ db.eval(function () {
+ function recursion() {
+ recursion.apply();
+ }
+ recursion();
+ });
+ }
+ assert.commandFailedWithCode(assert.throws(dbEvalRecursion), ErrorCodes.JSInterpreterFailure);
+
+ // Make sure mapReduce doesn't blow up
+ function mapReduceRecursion() {
+ db.recursion.mapReduce(function(){
+ (function recursion(){
+ recursion.apply();
+ })();
+ }, function(){
+ }, {
+ out: 'inline'
+ });
+ }
+
+ db.recursion.insert({});
+ assert.commandFailedWithCode(
+ assert.throws(mapReduceRecursion), ErrorCodes.JSInterpreterFailure);
+}());