LearnNewsExamplesServices
Frontmatter
id7025
titleFix: EffectBatchManager.endBatch() Infinite Loop Prevention
stateClosed
labels
enhancement
assigneestobiu
createdAtJul 12, 2025, 7:54 PM
updatedAtJul 12, 2025, 7:56 PM
githubUrlhttps://github.com/neomjs/neo/issues/7025
authortobiu
commentsCount0
parentIssue6992
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJul 12, 2025, 7:56 PM

Fix: EffectBatchManager.endBatch() Infinite Loop Prevention

Closed v10.0.0-beta.6 enhancement
tobiu
tobiu commented on Jul 12, 2025, 7:54 PM

Describe the bug The EffectBatchManager.endBatch() method, responsible for executing pending effects, had a subtle bug that could lead to an infinite loop. If an effect being run within the forEach loop caused another effect (or itself) to be re-queued into pendingEffects synchronously, it could result in the forEach iterating indefinitely or triggering subsequent endBatch() calls in a recursive manner.

To Reproduce Steps to reproduce the behavior:

  1. Have an Neo.core.Effect (Effect A) that, when run, triggers a reactive change.
  2. Have another Neo.core.Effect (Effect B) that depends on the reactive change caused by Effect A.
  3. If Effect A is processed by EffectBatchManager.endBatch() and its execution synchronously causes Effect B to be re-queued into pendingEffects (or if Effect A itself is re-queued), it could lead to an infinite loop within the endBatch()'s forEach iteration.

Expected behavior The EffectBatchManager.endBatch() should process all pending effects in a given batch without re-triggering effects within the same batch, even if their execution causes new effects to be queued.

Solution To prevent this, EffectBatchManager.endBatch() now creates a snapshot of pendingEffects (using Array.from()) and clears the original pendingEffects Set before iterating and running the effects. This ensures that any new effects queued during the execution of the current batch are added to a new batch, preventing interference with the current processing and breaking the synchronous infinite loop.

Impact This bug could lead to application freezes and "Maximum call stack size exceeded" errors in scenarios where effects trigger other effects synchronously within a batch.

Affected Files src/core/EffectBatchManager.mjs

tobiu assigned to @tobiu on Jul 12, 2025, 7:54 PM
tobiu added the enhancement label on Jul 12, 2025, 7:54 PM
tobiu referenced in commit 98ff9b1 - "Fix: EffectBatchManager.endBatch() Infinite Loop Prevention #7025" on Jul 12, 2025, 7:56 PM
tobiu closed this issue on Jul 12, 2025, 7:56 PM
tobiu added parent issue #6992 on Jul 12, 2025, 8:27 PM