Comments (8)
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.
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
whenmax_stack_size
is set withu64::MAX
. Without setting any max_stack_size, it returns a proper errorInternalError: 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.
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.
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.
hmm, that also is an issue with the eventloop not triggering properly, i'll look into it asap
from quickjs_es_runtime.
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.
There seems to be an issue with
setInterval
from the below code, you could see it printssetInterval 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.
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)
- Leaked promise inside a dropped context causes panic! HOT 7
- timeouts on invocations like call_function and eval HOT 2
- Ability to load pre-compiled modules HOT 11
- Option to disable features - console, setTimeout, setInterval HOT 9
- add console_formatter / console_logger to builder HOT 1
- Feat: function and struct to compute memory usage HOT 1
- Feat: TypedArrays HOT 1
- Panicked when running multiple promises concurrently HOT 2
- Document js_utils methods
- deprecate EsValueFacade HOT 1
- Segmentation fault: 11 & panic when using ScriptModuleLoader<QuickJsRealmAdapter> HOT 7
- fix MemoryUsage impl
- respect memory limit
- Main thread gets stuck randomly while awaiting for promise HOT 18
- thread panic occurred HOT 6
- Support for serde_json HOT 10
- Unexpected error logs even when the promise rejection is handled HOT 7
- Tokio Version in cargo.toml HOT 5
- Typescript support HOT 7
- fork quickjs HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quickjs_es_runtime.