Skip to content

Fix infinite loop detection false trigger on await in loops (#4295) - #4302

Open
sarthaklole wants to merge 1 commit into
processing:developfrom
sarthaklole:develop
Open

Fix infinite loop detection false trigger on await in loops (#4295)#4302
sarthaklole wants to merge 1 commit into
processing:developfrom
sarthaklole:develop

Conversation

@sarthaklole

Copy link
Copy Markdown

Issue:

Fixes #4295

Using asynchronous resource loading methods (such as await loadImage(...)) inside loops within async function setup() or other async functions caused false-positive "Infinite loop detected" errors.

Root Cause

Loop timer variables stored a primitive timestamp (var _LP0 = Date.now();) initialized once before the loop started. When await paused execution while yielding control to the event loop (such as during network requests), wall-clock time elapsed. Upon await resolving and loop execution resuming, Date.now() - _LP0 > 100 evaluated to true, falsely triggering loopProtect.hit().

Demo:

N/A (Non-UI code transformation logic fix)

Changes:

  • client/utils/previewEntry.js: Added reset: function(loopObj, val) to window.loopProtect that refreshes the loop timer timestamp (loopObj.t = Date.now()) after an await expression resolves and passes through the resolved value.
  • client/modules/Preview/jsPreprocess.js:
    • Initialized loop protection timer variables as objects (var _LP0 = { t: Date.now() };).
    • Updated loop timeout check to test Date.now() - _LP0.t > 100.
    • Transformed AwaitExpression nodes inside protected loops to wrap them with window.loopProtect.reset(_LPx, awaitExpr) (supporting single and nested loops).
  • client/modules/Preview/jsPreprocess.unit.test.js: Added unit tests for async/await loop protection to verify wrapping behavior and nested loop support.

I have verified that this pull request:

  • has no linting errors (npm run lint)
  • has no test errors (npm run test)
  • has no typecheck errors (npm run typecheck)
  • is from a uniquely-named feature branch and is up to date with the develop branch.
  • is descriptively named and links to an issue number, i.e. Fixes #123
  • meets the standards outlined in the accessibility guidelines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite loop detection triggers on await loadImage etc in setup

1 participant