The http request script is unresponsive

After an http request, the callback does not return and a deadlock occurs.
lock The inner block is not reached.
The action function cannot be called, so the callback cannot be received.

Schema : Update Script Test

function request(method, url, body, headers) {
    return new Promise((resolve, reject) => {
        try {
            if (method === 'GET') {
                getJSON(url, (data) => {
                    resolve(data);
                }, headers, true);
            }
            else if (method === 'POST') {
                postJSON(url, body, (data) => {
                    resolve(data);
                }, headers, true);
            }
            else if (method === 'PUT') {
                putJSON(url, body, (data) => {
                    resolve(data);
                }, headers, true);
            }
            else if (method === 'DELETE') {
                deleteJSON(url, (data) => {
                    resolve(data);
                }, headers, true);
            } else {
                reject('not support requst method');
            }
        } catch(ex) {
            reject(ex);
        }
    });
}

(async () => {
    
    const headers = {
        'Content-Type': `application/json`
    };
    
    try {
        await request('PUT', 'http://localhost:5000/health', {}, headers);
    } catch(ex) {
        reject(`xx : ${ex}`);
    }
})()strong text

I confirmed that Evaluate did not return due to the await section while executing the script code.

    public override JsValue Evaluate(Prepared<Script> script)
    {
        lock (Engine)
        {
            return Engine.Evaluate(script);
        }
    }

Could be a problem of your promise stuff, but I am 100% sure that it works in general. I have never tested it with promises.

But I think getJSON does not even exist in Evaluate, because this is only meant for sync expressions like variable evaluations.

hi. @Sebastian
I wrote a simple script that reproduces the problem 100%.
The first time I run Evaluate, I get a lock, but it doesn’t return, and when I try to make an http request and pass a callback, a deadlock occurs when I enter the second lock.

function AsyncContext() {
    return new Promise((resolve, reject) => {
        getJSON('https://support.oneskyapp.com/hc/en-us/article_attachments/202761627', (data) => {
            resolve(data);
        }, {}, true);
    });
}

(async () => {
    await AsyncContext();
    complete()
})()

I have changed it to a feature request. It was never intended to work with promises as promises was not available in at the beginning when the script engine was introduced. PRs would be awesome, but I get it is tricky to fix it.

thank you, Sebastian
I’m just getting started with Squidex.
I’ve recently started using Squidex, so I’m still struggling to understand its structure.

I have pushed a fix whereI removed the initial lock and it seems to work fine.