denoland / deno_core

The core engine at the heart of Deno
MIT License
263 stars 85 forks source link

Possible bugs in resource recovery #192

Closed paomian closed 8 months ago

paomian commented 1 year ago

I'm using deno_core ember my project to eval js code to calc some encrypt logic.

    fn eval_js(&self, js_enc: &str, code: &String) -> Result<Value> {
        let mut runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions::default());
        let _ = runtime.execute_script(
            "<crypt_js>",
            deno_core::FastString::Owned(self.crypto_js.clone().into()),
        );
        let _ = runtime.execute_script("<encrype>", deno_core::FastString::Owned(js_enc.into()));
        let res =
            runtime.execute_script("<code>", deno_core::FastString::Owned(code.clone().into()));
        match res {
            Ok(global) => {
                let scope = &mut runtime.handle_scope();
                let local = deno_core::v8::Local::new(scope, global);
                let deserialized_value = serde_v8::from_v8::<serde_json::Value>(scope, local);
                match deserialized_value {
                    Ok(value) => Ok(value),
                    Err(_) => Err(DouyuError::CryptoJsError),
                }
            }
            Err(_) => Err(DouyuError::CryptoJsError),
        }
    }

Some bugs may be triggered randomly whenever resources are recovered. "Segmentation fault" when eval_js is called multiple times I debug it with gdb get this bt. The sixteenth line of the stack is the line number of the last line of my code above. Is there something wrong with the way I'm using it?

#0  0x00005564405b37b3 in v8::internal::ThreadIsolation::UnregisterJitPage(unsigned long, unsigned long, v8::internal::ThreadIsolation::AllocationSource) () at ../../../../v8/src/common/code-memory-access.cc:364
#1  0x000055643fda1b69 in v8::internal::MemoryAllocator::PreFreeMemory(v8::internal::MemoryChunk*) () at ../../../../v8/src/heap/memory-allocator.cc:527
#2  0x000055643fda1bcd in v8::internal::MemoryAllocator::Free(v8::internal::MemoryAllocator::FreeMode, v8::internal::MemoryChunk*) () at ../../../../v8/src/heap/memory-allocator.cc:563
#3  0x000055643fdc06c8 in v8::internal::PagedSpaceBase::TearDown() () at ../../../../v8/src/heap/paged-spaces.cc:146
#4  0x000055643fd6e852 in v8::internal::PagedSpace::~PagedSpace() () at ../../../../v8/src/heap/paged-spaces.h:392
#5  0x000055643fd6e79e in v8::internal::CodeSpace::~CodeSpace() () at ../../../../v8/src/heap/paged-spaces.h:500
#6  0x000055643fd644e3 in v8::internal::Heap::TearDown() () at ../../../../v8/src/heap/heap.cc:5944
#7  0x000055643fd0ea92 in Deinit () at ../../../../v8/src/execution/isolate.cc:3741
#8  0x000055643fd0e52a in v8::internal::Isolate::Delete(v8::internal::Isolate*) () at ../../../../v8/src/execution/isolate.cc:3455
#9  0x000055643fc5021b in v8::isolate::Isolate::dispose (self=0x7fe72c010d60) at src/isolate.rs:1215
#10 0x000055643fc50685 in v8::isolate::{impl#8}::drop (self=0x7fe74d3e3e88) at src/isolate.rs:1505
#11 0x000055643fc336eb in core::ptr::drop_in_place<v8::isolate::OwnedIsolate> () at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ptr/mod.rs:497
#12 0x000055643fa14d3b in core::mem::manually_drop::ManuallyDrop<v8::isolate::OwnedIsolate>::drop<v8::isolate::OwnedIsolate> (slot=0x7fe74d3e3e88)
    at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/mem/manually_drop.rs:144
#13 0x000055643f975d6c in deno_core::runtime::jsruntime::{impl#4}::drop (self=0x7fe74d3e3e58) at runtime/jsruntime.rs:172
#14 0x000055643fa92b47 in core::ptr::drop_in_place<deno_core::runtime::jsruntime::InnerIsolateState> () at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ptr/mod.rs:497
#15 0x000055643fa9004e in core::ptr::drop_in_place<deno_core::runtime::jsruntime::JsRuntime> () at /rustc/5680fa18feaa87f3ff04063800aec256c3d4b4be/library/core/src/ptr/mod.rs:497
#16 0x000055643f7cbd78 in eval_js (self=0x556442efb048, js_enc=..., code=0x7fe74d3e5840) at src/src.rs:211
paomian commented 1 year ago

same to https://github.com/denoland/deno_core/issues/150