120 views

Description

SizeAwareness size estimation is additive when ScriptableObjects are instantiated in a loop causing the size of scriptable objects estimation to be larger than expected. This can result in scripts failing with the following exception in the logs:
 
WARNING *** WARNING *** Javascript compiler exception: Object object has exceeded maximum permitted size of 268435456 in:
 
Note: the Size Awareness feature was enabled in Jakarta so this exception will only be experienced on instances Jakarta+

Steps to Reproduce

 

  1. Create a global script include with the following logic:

    RhinoTest.prototype = {
    _taskRec: undefined,
    _commitmentsProcessed: [],
    initialize: function(_task) {
    this._commitmentsProcessed = [];
    if (_task != undefined) {
    if (typeof _task == 'object') {
    this._taskRec = _task;
    }
    }
    },
    type: 'RhinoTest'
    };
  2. Set the property glide.size.aware.max_size.org.mozilla.javascript.NativeObject to a smaller value than the default OOB.

    It was triggered with ascending values of 1mb (actual value is 1048576) and 4mb (or 4194304).

  3. Run the following in scripts background:

    //beginning of script
    function myFunction() {
       var x = new GlideRecord('task');
       x.query();
       while(x.next()){
          var y = new RhinoTest(x);
          }
       }
       
    myFunction();
    
    //end of script

    Note that after about 6 iterations or so, it hits the limit for a NativeObject of 1048576 bytes if the limit is set to 1048576.

  4. If the limit is doubled or quadrupled to 4194304, it yields double or quadruple the number of iterations triggered and this message will be logged:

    Object object has exceeded maximum permitted size of <value of property limit>

Workaround

Inspect the localhost logs looking for the "javascript compiler error" messages that are generated when the upper limit on the glide.size.aware.max_size.org.mozilla.javascript.NativeObject property is breached.  
 
The message will look like the following example and can be found in the localhost log and in the syslog table. 
 
WARNING *** WARNING *** Javascript compiler exception: Object object has exceeded maximum permitted size of 268435456 in:
 
Following this message will be the script that caused the issue.  You can use the script to search for the script include, business rule, ACL, etc., triggering the above message. 

To resolve the issue, review the script that triggered the message.

  • If the script is considered non-essential and can be disabled or if the script can be modified to prevent the looping object creation, that would be preferable to disabling the limit on the size.  In most cases observed, the property limit is breached when a script is calling a script include (or some other script for example a transform script) in a while loop and passing in a GlideRecord object in each iteration. The Steps to Reproduce provide a script example.

  • If the script is considered essential and if there are no out-of-memory issues, set the size aware property glide.size.aware.max_size.org.mozilla.javascript.NativeObject to -1 to disable the NativeObject size limit. This ensures that the limit on NativeObject types is not applied or, in other words, scriptable objects created via script.

    Not all scripts with a while loop that calls a script include will cause the problem, which is why reviewing the script is essential.

It might be possible to provide immediate relief by deactivating or modifying the script triggering the message. Review the script to see whether the looping script can be modified so that the logic does not unnecessarily loop and instantiate new script related objects.  This might be preferable to disabling the NativeObject limit. The limit is there to protect against unnecessarily large objects leading to out of memory conditions.  There may be scripts that do not trigger the conditions in this problem that could create large objects leading to low memory. 
 
If disabling the size limit on NativeObject is determined to be the best solution, then monitoring the instance memory usage after the change is made should be performed.

Related Problem: PRB1257374

Seen In

Jakarta

Intended Fix Version

Jakarta Patch 9
London

Fixed In

Kingston Patch 4

Safe Harbor Statement

This "Intended Fix Version" information is meant to outline ServiceNow's general product direction and should not be relied upon in making a purchasing decision. The information provided here is for information purposes only and may not be incorporated into any contract. It is not a commitment, promise, or legal obligation to deliver any material, code, or functionality. The development, release, and timing of any features or functionality described for our products remains at ServiceNow's sole discretion.

Associated Community Threads

There is no data to report.

Article Information

Last Updated:2018-04-17 01:52:47
Published:2018-03-29