Details
-
Bug
-
Resolution: Fixed
-
Critical
-
7.1.0
-
Untriaged
-
1
-
Yes
Description
Consider the following js function
function doSelect() {
|
var q = select * from `travel-sample`.inventory.route a;
|
var res = [];
|
for (const doc of q) { |
var q1 = insert into b2 values(UUID(), "1"); |
}
|
return res; |
}
|
(route has some 24K documents)
This fails with
{
|
"code": 10109,
|
"msg": "Error executing function 'test' (test:doSelect)",
|
"reason": {
|
"details": {
|
"Code": " q1 = N1QL('insert into b2 values(UUID(), \\\"1\\\");', {}, true);",
|
"Exception": " Active iterator limit of 10 reached. Close unused iterators and retry",
|
"Location": "functions/test.js:5",
|
"Stack": " at doSelect (functions/test.js:5:14)"
|
},
|
"type": "Exceptions from JS code"
|
}
|
}
|
In order to make this work, the function needs to be modified like this
function doSelect() {
|
var q = select * from `travel-sample`.inventory.route a;
|
var res = [];
|
for (const doc of q) { |
var q1 = insert into b2 values(UUID(), "1"); |
q1.close()
|
}
|
return res; |
}
|
Now the thing is, the INSERT in q1 returns no value, so the N1QL() function should have already pulled the next document, seen that it's empty and know that it has already been terminated, but from logging, I see that the previous iteration has not closed yet.
We should make sure that statements that do not return values are terminated straight away.
There is a wider discussion to be had as to how N1QL can notify jsevaluator of statements that it is closing automatically (which would be useful for DML that return values).