Skip to content

fix: guard y-axis tick loop against float stall - #849

Open
NemeZZiZZ wants to merge 1 commit into
klinecharts:mainfrom
NemeZZiZZ:fix/yaxis-tick-loop-stall-guard
Open

fix: guard y-axis tick loop against float stall#849
NemeZZiZZ wants to merge 1 commit into
klinecharts:mainfrom
NemeZZiZZ:fix/yaxis-tick-loop-stall-guard

Conversation

@NemeZZiZZ

Copy link
Copy Markdown
Contributor

Problem

The y-axis tick loop has no stall guard:

while (f <= last) {
  ...
  f += interval   // if interval < ULP(f)/2, f never changes → infinite loop
}

In IEEE-754, when interval is smaller than half the ULP of f, the addition leaves f unchanged and the loop never terminates — ticks grows without bound (frozen tab, eventually OOM).

Verified by execution: with a flat range at magnitude ~1e13 (ulp(1e13) ≈ 1.95e-3) — reachable because createRangeImp expands a degenerate range to TICK_COUNT * minSpan where minSpan = 1e-4 at precision 4 — interval = nice(8e-4 / 8) = 1e-4, and 1e13 + 1e-4 === 1e13. The loop did not terminate within 1,000,000 iterations, with f pinned at 10000000000000.

Fix

Break when the addition stops moving the accumulator:

const next = f + interval
if (next === f) { break }
f = next

Verification

  • Stall scenario: terminates after the first tick instead of hanging.
  • Normal cases byte-identical: [100,108] step 1 → 100..108 (9 ticks); [0.05,0.4] step 0.05 → 0.05..0.4 (8 ticks).

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.

1 participant