Fix infinite loop detection false trigger on await in loops (#4295) - #4302
Open
sarthaklole wants to merge 1 commit into
Open
Fix infinite loop detection false trigger on await in loops (#4295)#4302sarthaklole wants to merge 1 commit into
sarthaklole wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue:
Fixes #4295
Using asynchronous resource loading methods (such as
await loadImage(...)) inside loops withinasync 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. Whenawaitpaused execution while yielding control to the event loop (such as during network requests), wall-clock time elapsed. Uponawaitresolving and loop execution resuming,Date.now() - _LP0 > 100evaluated totrue, falsely triggeringloopProtect.hit().Demo:
N/A (Non-UI code transformation logic fix)
Changes:
client/utils/previewEntry.js: Addedreset: function(loopObj, val)towindow.loopProtectthat refreshes the loop timer timestamp (loopObj.t = Date.now()) after anawaitexpression resolves and passes through the resolved value.client/modules/Preview/jsPreprocess.js:var _LP0 = { t: Date.now() };).Date.now() - _LP0.t > 100.AwaitExpressionnodes inside protected loops to wrap them withwindow.loopProtect.reset(_LPx, awaitExpr)(supporting single and nested loops).client/modules/Preview/jsPreprocess.unit.test.js: Added unit tests forasync/awaitloop protection to verify wrapping behavior and nested loop support.I have verified that this pull request:
npm run lint)npm run test)npm run typecheck)developbranch.Fixes #123