Error Reference

Stack overflow: maximum call stack size exceeded

Stack overflow: maximum call stack size exceeded

Where this appears

This error appears in the ServiceNow browser console, System Log, or application error messages when JavaScript code enters infinite recursion. It commonly occurs during Business Rule execution, Script Include functions, or client-side scripts when recursive function calls exhaust the JavaScript engine's call stack memory.

Sourdough
Chrome Extension

Debugging this in a real instance?

Sourdough lets you trace "Stack overflow: maximum call stack size exceeded" through system logs, script errors, and API health in the ServiceNow tab you are already using.

Add to Chrome

Free to install. Pro $5/month after a 14-day no-card trial.
Pro requires the ServiceNow admin role. Upgrade inside the extension.

Overview
Tasks
CMDB
API
Metrics
Monitor
Internals
Instance:sourdoughdev·Version:Yokohama
Instance StateONLINE
System StatusFully Operational
Session Timeout90 minutes
Logged-In Sessions2 (20 active)
Build Nameyokohama-12-18-2024_p1
IP Address10.159.128.43
Instance HealthHealth Score: 90%
🔥 5dSourdough (Chrome Plugin)Dark Mode

Cause

A Business Rule triggers itself repeatedly through database operations (insert, update, delete) without proper exit conditions or infinite loop protection. (high likelihood)

Recursive Script Include functions lack a proper base case or termination condition, causing endless self-calls during GlideRecord queries or data processing. (high likelihood)

Multiple Business Rules create a circular chain of triggers where Rule A modifies records that trigger Rule B, which modifies records that trigger Rule A again. (medium likelihood)

Client Scripts or UI Actions contain recursive function calls that execute indefinitely due to missing or incorrect termination logic in form processing. (medium likelihood)

Workflow activities or custom scripted activities call themselves or create circular dependencies between workflow states without proper exit conditions. (low likelihood)

Fix

Step 1: Navigate to System Diagnostics > Log > Application Log and filter by 'stack overflow' or 'maximum call stack' to identify the exact script and line number causing the recursion.

Step 2: Examine the identified script (Business Rule, Script Include, or Client Script) and trace through the function calls to identify where recursion occurs without termination.

Step 3: Check for Business Rules that modify the same table they are triggered on by reviewing the 'When to run' conditions and ensuring proper filtering to prevent self-triggering.

Step 4: Add proper base case conditions to recursive functions by implementing counter variables, depth limits, or specific exit criteria before recursive calls are made.

Step 5: Use the Business Rule debugger or add gs.log() statements at function entry points to track recursion depth and identify the exact recursion pattern.

Step 6: Implement recursion guards using static variables or GlideSystem properties to track function call depth and exit when a maximum threshold is reached.

Step 7: Test the corrected script in a sub-production instance with representative data to verify the recursion is eliminated without breaking intended functionality.

Step 8: Monitor the System Log after deployment for 24-48 hours to ensure the stack overflow error no longer occurs during normal system operations.

Test Your Knowledge

Quick 3-question quiz. See how your ServiceNow skills stack up.

Question 1 of 3Performance

A list view on a table with millions of records is slow. Best fix?

Select an answer to continue