Blocking script

hi. @Sebastian
I’m investigating additional script issues.

I’m sharing a 100% reproducible script.

If you return promiseMethod as a promise, it blocks.

However, if you change it to
await promiseMethod();

it responds normally.

                function promiseMethod() {
                    return new Promise((resolve, reject) => {
                        getJSON('http://cloud.squidex.io/healthz', (data) => {
                            reject('test');
                        }, {}, true);
                    });
                }

                async function asyncMethod() {
                    try {
                       /* Success Case
                        return await promiseMethod();
                      */

                        // Blocking
                        return promiseMethod();
                    }
                    catch(ex)
                    {
                        throw ex;
                    }
                }

                (async () => {
                    try {
                        await asyncMethod();
                        complete()
                    }
                    catch(ex)
                    {
                        reject(ex);
                    }
                })()

Have you tried it with the latest fix?

Yes, I’m testing against the latest commit.
I’ve debugged this issue multiple times, but it seems to be a different bug.

If you want to provide a PR, It would be super nice. At least a guard that protects the request from timing out.

The Jint version used by Squidex doesn’t even timeout.
However, after updating to the latest version of Jint, I’m still getting timeout errors.
I’m investigating whether this is a Jint issue.
I’ll take a look, but I’m not confident about PR yet.

I don’t expect that to be done asap. But I am not sure if jint can protect from deadlocks.

I tested it by upgrading jint versions one by one. The engine timeout issue due to a promise issue was resolved in minversion 4.3.0, #2103
I simplified the script a bit.
however, the blocking issue persists when using the async keyword.
It seems that upgrading at least allows for timeout protection.

my personal opinion is that it might be a jint issue.
could you consider upgrading the version to resolve the timeout issue?

[Fact]
    public async Task Should_run_with_promises1()
    {
        var vars = new DataScriptVars();

        const string script = @"
                function promiseMethod() {
                    return new Promise((resolve, reject) => {
                        getJSON('http://cloud.squidex.io/healthz', (data) => {
                            resolve(42);
                        }, {}, true);
                    });
                }

                // async blocking
                async function asyncMethod() {
                    return promiseMethod();
                }

                (async () => {
                    try {
                        let value = await asyncMethod();
                        complete(value)
                    }
                    catch(ex)
                    {
                        reject(ex);
                    }
                })()
            ";

        var result = await sut.ExecuteAsync(vars, script, contentOptions);

        Assert.Equal(42.0, result.Value);
    }