Skip to content

Concurrent evaluate() calls lead to unexpected results #804

@mpauly-exnaton

Description

@mpauly-exnaton

Assume you have a compiled jsonata Expression. When calling evaluate() on this Expression concurrently, then $$ appears to resolve to the same underlying object for all evaluate() calls. As a result, one gets unexpected results.

Example - full repro here:

const expression = `
{
  "id": $$.id,
  "delayed": $slow($$.id)
}
`;

const compiled = jsonata(expression);
...
[
  { id: "aaaaaaaa" },
  { id: "bbbbbbbb" },
  { id: "cccccccc" },
].map((input) => compiled.evaluate(input))

only outputs id cccccccc. The slow async function is part of the expression to amplify the problem.

As an upstream fix, my LLM suggested to create a separate frame per invocation instead of reusing the shared environment. I validated that this fixes the problem, however I am not deep enough in the jsonata source to understand whether this is a sensible fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

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