rusty_v8 icon indicating copy to clipboard operation
rusty_v8 copied to clipboard

OOM after save global function in release

Open lazytiger opened this issue 1 year ago • 0 comments

I need to save some global functions to be called after.

let key = v8::String::new(scope, "SetPromiseRejectCallback")?;
    let value = Function::new(
        scope,
        |scope: &mut HandleScope, args: FunctionCallbackArguments, _rv: ReturnValue| {
            let callback: Local<Function> = if let Ok(v) = args.get(0).try_into() {
                v
            } else {
                let exp = v8::String::new(scope, "the last parameter must be function").unwrap();
                let exp = Exception::error(scope, exp);
                scope.throw_exception(exp);
                return;
            };
            let callback = Global::new(scope, callback);
            engine_mut().promise_reject_callback = Some(callback);
        },
    )?;

But always got a OOM after engine_mut().promise_reject_callback = Some(callback); if compiled with release

<--- Last few GCs --->

[14652:0000018918B70000]    33069 ms: Scavenge 1397.1 (1400.4) -> 1396.0 (1400.9) MB, pooled: 0 MB, 3.38 / 0.00 ms  (average mu = 0.172, current mu = 0.117) allocation failure; 
[14652:0000018918B70000]    33952 ms: Mark-Compact (reduce) 1396.2 (1400.9) -> 1396.1 (1398.1) MB, pooled: 0 MB, 878.57 / 0.00 ms  (+ 0.1 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 882 ms) (average mu = 0.12

<--- JS stacktrace --->



#
# Fatal JavaScript out of memory: Ineffective mark-compacts near heap limit
#
==== C stack trace ===============================

	CrashForExceptionInNonABICompliantCodeRange [0x00007FFEF6E3DD3B+1311899]
	v8_inspector__V8InspectorClient__BASE__ensureDefaultContextInGroup [0x00007FFEF6B4ACB7+139335]
	v8_inspector__V8InspectorClient__BASE__ensureDefaultContextInGroup [0x00007FFEF6B9A77A+465674]
	v8_inspector__V8InspectorClient__BASE__ensureDefaultContextInGroup [0x00007FFEF6B360CC+54364]
	v8_inspector__V8InspectorClient__BASE__ensureDefaultContextInGroup [0x00007FFEF6C216A7+1018423]
	v8_inspector__V8InspectorClient__BASE__ensureDefaultContextInGroup [0x00007FFEF6C36064+1102836]
	v8_inspector__V8InspectorClient__BASE__ensureDefaultContextInGroup [0x00007FFEF6C357EB+1100667]
	CrashForExceptionInNonABICompliantCodeRange [0x00007FFEF7FEAD2D+19846285]
	v8_inspector__V8InspectorClient__BASE__ensureDefaultContextInGroup [0x00007FFEF6C1F307+1009303]
	CrashForExceptionInNonABICompliantCodeRange [0x00007FFEF6E0C110+1108080]
	CrashForExceptionInNonABICompliantCodeRange [0x00007FFEF74F668C+8359404]
	CrashForExceptionInNonABICompliantCodeRange [0x00007FFEF7EB69BA+18583834]
	CrashForExceptionInNonABICompliantCodeRange [0x00007FFEF7EAFFFC+18556764]
	(No symbol) [0x00007FFE78001D9C]

What's weird is the following code works fine

let key = v8::String::new(scope, "registerTick")?;
    let value = Function::new(
        scope,
        |scope: &mut HandleScope, args: FunctionCallbackArguments, _rv: ReturnValue| {
            let callback: Local<Function> = if let Ok(v) = args.get(0).try_into() {
                v
            } else {
                let exp = v8::String::new(scope, "the last parameter must be function").unwrap();
                let exp = Exception::error(scope, exp);
                scope.throw_exception(exp);
                return;
            };
            let callback = Global::new(scope, callback);
            engine_mut().ticks.push(Arc::new(Box::new(move || {
                let callback = callback.clone();
                run_in_context_scope(move |scope| {
                    let callback = Local::new(scope, callback);
                    let recv = v8::null(scope);
                    callback.call(scope, recv.into(), &[]).map(|_| ())
                });
            })));
        },
    )?;

lazytiger avatar Oct 15 '24 23:10 lazytiger