Skip to content

Fix Eval hang on an evaluated Memoize with no continuations left - #4002

Open
ptweezy wants to merge 1 commit into
arrow-kt:mainfrom
ptweezy:fix/eval-memoize-hang
Open

ptweezy wants to merge 1 commit into
arrow-kt:mainfrom
ptweezy:fix/eval-memoize-hang

Conversation

@ptweezy

@ptweezy ptweezy commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Eval.evaluate loops forever when it reaches a Memoize that already has a value and no continuations are left, because curr never changes:

val m = Eval.now(1).map { it + 1 }.memoize()
m.value()
Eval.now(0).flatMap { m }.value() // never returns

This sets curr = Now(it), as the FlatMap branch already does for a cached Memoize. SuspendEval.evaluate has the same bug and fix.

Found while checking #4001. The new tests in EvalTest and SuspendEvalTest hang without the fix. arrow-eval's JVM tests pass; I didn't run the other targets locally.

evaluate never updated curr when it reached a Memoize that already had
a value and the continuation stack was empty, so it looped forever:

  val m = Eval.now(1).map { it + 1 }.memoize()
  m.value()
  Eval.now(0).flatMap { m }.value() // never returns

Treat the cached value as Now(it), as the FlatMap branch already does.
Same fix in SuspendEval.
@ptweezy
ptweezy force-pushed the fix/eval-memoize-hang branch from 981b7dc to a2cc386 Compare November 5, 2026 16:07

This branch has not been deployed

No deployments
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