Skip to content

Issue with true 'parallel' async method - ReferenceError: Variable "param1" is not defined #317

Description

@cyrildurand

I encounter an error with async method on my production environment.

I'm not sure how to explain it but I could reproduce it with this minimal code sample

    [TestMethod]
    public void TestParallelAsync()
    {
        var script = Script.Parse(@"
export default async function(param1) {
    return param1?.value
}
");
        var context = new GlobalContext();
        var module = new Module($"main.js", script, context);
        module.Run();

        var run = module.Exports.Default.As<Function>();
        var tasks = Enumerable.Range(0, 10)
                              .Select(async i =>
                              {
                                  await Task.Yield();
                                  var result = run.Call(new Arguments() { null, new { value = "b" } });

                                  return await ((Promise)result.Value).Task;
                              });

        var task = Task.WhenAll(tasks);


        var values = task.GetAwaiter().GetResult();
        Assert.AreEqual("b", values[0].As<string>());
        Assert.AreEqual("b", values[1].As<string>());
    }

Without Task.Yield() we don't have any error.

Let me know if you need further information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions