[SERVER-22715] Add an assert to Array.shuffle Created: 18/Feb/16  Updated: 24/Feb/16  Resolved: 19/Feb/16

Status: Closed
Project: Core Server
Component/s: JavaScript, Shell
Affects Version/s: 3.3.1
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Robert Guo (Inactive) Assignee: Robert Guo (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
Backwards Compatibility: Fully Compatible
Sprint: TIG 10 (02/19/16), TIG 11 (03/11/16)
Participants:
Linked BF Score: 0

 Description   

Array.shuffle becomes an infinite loop if we do the following:

Random.randint = NumberLong

We should assert that we're not growing the array in Array.shuffle



 Comments   
Comment by Robert Guo (Inactive) [ 19/Feb/16 ]

This approach will not solve the problem given that assert could be overridden as well.

Closing as a won't fix

Comment by Mira Carey [ 18/Feb/16 ]

Interesting. I've played around with the form a few different ways and it looks like there's some combination of a hard limit on the number of array elements: 262,143,998. and an out of memory error on the horizon.

The shuffle looks like it'll eventually get there (OOM or too many array elements).

It wouldn't be terribly hard to offer a timer that stopped running computation though. Something like:

try {
var guard = new Guard(1000 /* ms */);
while (1) { spin(); }
guard.disable();
} catch (e) {
  // handle a new timed out exception
}

Comment by Robert Guo (Inactive) [ 18/Feb/16 ]

Seems to be neither. The interpreter errors out after a few seconds.

> while (1) {a[a.length] = 1}
2016-02-17T19:49:42.328-0500 E QUERY    [thread1] Unknown Failure from JSInterpreter

Comment by Mira Carey [ 18/Feb/16 ]

Does it actually infinite loop, or does it eventually get OOM killed?

If so, you might be able to attach that under SERVER-22688

Generated at Thu Feb 08 04:01:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.