GithubHelp home page GithubHelp logo

Comments (8)

andrieshiemstra avatar andrieshiemstra commented on May 28, 2024 1

ah, the problem was again in the EventLoop in utils, the deadline for the next run was calculated before actually running the timeout jobs, so the new one was not yet present in the list and thus eventloop fell back to the 10 sec default.. fixed in utils 0.1.3

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on May 28, 2024 1

Setting max_stack_size to u64::MAX works, but it's better not to set to a MAX value as I would like to prevent too many nested function calls.

e.g.

The above code causes a crash with fatal runtime error: stack overflow when max_stack_size is set with u64::MAX. Without setting any max_stack_size, it returns a proper error InternalError: stack overflow at at a (basics.es:3)

agreed, but I need a new version of quickjs to fix this (theduke/quickjs-rs#116)

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on May 28, 2024

Nice catch! thanks!

The problem was actually in the EventLoop in utils, i published a 0.1.2 version which fixes this, if you are using a quickjs_es_runtime which depends on utils = "0.1" it should update to the fixed version if you do a clean build.

Kind regards

from quickjs_es_runtime.

SreeniIO avatar SreeniIO commented on May 28, 2024
use futures::executor::block_on;
use hirofa_utils::js_utils::Script;
use log::LevelFilter;
use quickjs_runtime::esruntime::EsRuntime;
use quickjs_runtime::esruntimebuilder::EsRuntimeBuilder;
use std::sync::Arc;

async fn test(rt: Arc<EsRuntime>) {
    let res = rt
        .eval(Script::new(
            "basics.es",
            r#"
            new Promise((resolve) => {
                setTimeout(() => {
                    console.log('in timeout 1');
                    setTimeout(() => {
                        console.log('in timeout 2'); // this should get printed in 2 seconds
                        resolve(true);
                    }, 1000); // > 10s works as expected, but < 10s always takes 10 seconds
                }, 1000);
            });
        "#,
        ))
        .await
        .ok()
        .unwrap();

    let fut = res.get_promise_result();
    let val = fut.await;
    println!("{:?}", val);
}

fn main() {
    simple_logging::log_to_stderr(LevelFilter::Info);
    let rt = EsRuntimeBuilder::new().build();
    block_on(test(rt));
}

In the above sample code, the 2nd console.log is getting printed after 10 seconds irrespective of the timeout value. But if the timeout value is more than 10 seconds, then it's waiting as expected.

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on May 28, 2024

hmm, that also is an issue with the eventloop not triggering properly, i'll look into it asap

from quickjs_es_runtime.

SreeniIO avatar SreeniIO commented on May 28, 2024

There seems to be an issue with setInterval from the below code, you could see it prints setInterval func failed: InternalError: stack overflow at every second whenever the setInterval is triggered...

use futures::executor::block_on;
use hirofa_utils::js_utils::Script;
use log::LevelFilter;
use quickjs_runtime::esruntime::EsRuntime;
use quickjs_runtime::esruntimebuilder::EsRuntimeBuilder;
use std::sync::Arc;

async fn test(rt: Arc<EsRuntime>) {
    let res = rt
        .eval(Script::new(
            "basics.es",
            r#"
            setInterval(() => {
                console.log('in setInterval 1');
            }, 1000);
            new Promise((resolve) => {
                setTimeout(() => {
                        resolve(true);
                }, 10000);
            });
        "#,
        ))
        .await
        .ok()
        .unwrap();

    let fut = res.get_promise_result();
    let val = fut.await;
    println!("{:?}", val);
}

fn main() {
    simple_logging::log_to_stderr(LevelFilter::Info);
    let rt = EsRuntimeBuilder::new().build();
    block_on(test(rt));
}

from quickjs_es_runtime.

andrieshiemstra avatar andrieshiemstra commented on May 28, 2024

There seems to be an issue with setInterval from the below code, you could see it prints setInterval func failed: InternalError: stack overflow at every second whenever the setInterval is triggered...

I am unable to reproduce this, it works as expected for me but it might be an issue with the stack overflow check in quickjs.

Could you start the runtime with adding this to the builder?

let rt = EsRuntimeBuilder::new().max_stack_size(u64::MAX).build();

The quickjs stack check has a tendancy to overflow (from a negative number to a large positive number) causing it to think the stack is realy large.

I think thats why they added JS_UpdateStackTop() (see https://bellard.org/quickjs/Changelog) but i have not implemented that yet (see #50)

from quickjs_es_runtime.

SreeniIO avatar SreeniIO commented on May 28, 2024

Setting max_stack_size to u64::MAX works, but it's better not to set to a MAX value as I would like to prevent too many nested function calls.

e.g.

function a(counter) {
    console.log(counter);
    b(++counter);
}
function b(counter) {
    a(++counter);
}
a(1);

The above code causes a crash with fatal runtime error: stack overflow when max_stack_size is set with u64::MAX. Without setting any max_stack_size, it returns a proper error InternalError: stack overflow at at a (basics.es:3)

from quickjs_es_runtime.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.