Skip to content

TransientSolver has no timeout or step limit — simulation can hang indefinitely or exhaust memory #1

Description

@amaydixit11

TransientSolver's solve() method (src/simulation/TransientSolver.js, line 78) runs a while (this.time <= this.endTime) loop with no maximum iteration cap.

Problem

For small time steps or complex circuits, the solver can run millions of iterations without any guard.

Impact

  • For a 10ms simulation at 100µs step, that's 100 iterations (fine)
  • But if a user sets endTime=1s and timeStep=1µs, that's 1,000,000 matrix solves
  • All results are accumulated in this.results Map — memory grows linearly with iterations
  • No way to cancel — the UI thread blocks until completion

Fix

const maxSteps = 100000; // Cap
let stepCount = 0;
while (this.time <= this.endTime) {
    stepCount++;
    if (stepCount > maxSteps) return { success: false, error: `Exceeded max ${maxSteps} simulation steps` }
    ...
}

Or use AsyncGenerator to yield after N steps, allowing UI cancellation.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedExtra attention is needed

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions