Closed danthegoodman1 closed 1 month ago
I believe I solved it.
The way is to first setup a heap_limit_callback
callback that points to the isolate:
extern "C" fn oom_handler(_: *const std::os::raw::c_char, _: &v8::OomDetails) {
panic!("OOM! I should never happen")
}
isolate.set_oom_error_handler(oom_handler);
extern "C" fn heap_limit_callback(
data: *mut c_void,
current_heap_limit: usize,
_initial_heap_limit: usize,
) -> usize {
let isolate = unsafe {&mut *(data as *mut v8::Isolate)};
// murder the isolate
let terminated = isolate.terminate_execution();
println!("near limit! {:?}", terminated);
current_heap_limit * 2 // give us some space to kill it
}
let isolate_ptr: &mut v8::Isolate = &mut isolate;
// Cast the isolate pointer to *mut c_void
let data: *mut c_void = isolate_ptr as *mut v8::Isolate as *mut c_void;
isolate.add_near_heap_limit_callback(heap_limit_callback, data);
When you kill the isolate while it is running, the expected failure happens:
let result = match multiply_fn.call(&mut scope, instance.into(), args) {
Some(result) => {
println!("result");
result
}
None => {
println!("Has caught: {}, can continue: {}", scope.has_caught(), scope.can_continue());
panic!("exiting now")
}
};
How do you catch when an isolate runs out of a configured heap limit like:
It seems to crash the whole rust currently: