Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main Isolate deadlock on isolate disposal #302

Closed
marcusdarmstrong opened this issue May 3, 2022 · 2 comments
Closed

Main Isolate deadlock on isolate disposal #302

marcusdarmstrong opened this issue May 3, 2022 · 2 comments

Comments

@marcusdarmstrong
Copy link

Hi there!

We've recently discovered that isolated-vm can cause a main-thread deadlock when attempting to dispose of isolates. This appears to occur when a promise from the main isolate is pending and proxied into the to-be-disposed isolate. Given that it looks like you're no longer actively maintaining the project I'd be happy to contribute a fix if I could be pointed in the right direction.

Reproduction script:

const ivm = require('isolated-vm');
setInterval(() => { console.log("Event Loop is running"); }, 100); // Never logged.
const isolate = new ivm.Isolate();
const context = isolate.createContextSync();
context.global.setSync("getProm", () => new Promise(() => {}), { reference: true });
context.eval("getProm.applySync()");
context.release();
console.log(`Context released`);
isolate.dispose();
console.log(`Isolate disposed`); // Never logged

Process sample:

Sampling process 23338 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling node (pid 23338) every 1 millisecond
Process:         node [23338]
Path:            /Users/USER/*/node
Load Address:    0x100c64000
Identifier:      node
Version:         0
Code Type:       X86-64
Platform:        macOS
Parent Process:  zsh [74283]

Date/Time:       2022-05-03 09:16:13.808 -0400
Launch Time:     2022-05-03 09:16:08.636 -0400
OS Version:      macOS 11.6 (20G165)
Report Version:  7
Analysis Tool:   /usr/bin/sample

Physical footprint:         10.2M
Physical footprint (peak):  10.2M
----

Call graph:
    2848 Thread_118355832   DispatchQueue_1: com.apple.main-thread  (serial)
    + 2848 start  (in libdyld.dylib) + 1  [0x7fff204e4f3d]
    +   2848 node::Start(int, char**)  (in node) + 200  [0x100cfe5a8]
    +     2848 node::NodeMainInstance::Run(node::EnvSerializeInfo const*)  (in node) + 121  [0x100d74cd9]
    +       2848 node::NodeMainInstance::Run(int*, node::Environment*)  (in node) + 61  [0x100d7502d]
    +         2848 node::LoadEnvironment(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>)  (in node) + 109  [0x100c6a4dd]
    +           2848 node::StartExecution(node::Environment*, std::__1::function<v8::MaybeLocal<v8::Value> (node::StartExecutionCallbackInfo const&)>)  (in node) + 800  [0x100cfc260]
    +             2848 node::StartExecution(node::Environment*, char const*)  (in node) + 374  [0x100cfc516]
    +               2848 node::ExecuteBootstrapper(node::Environment*, char const*, std::__1::vector<v8::Local<v8::String>, std::__1::allocator<v8::Local<v8::String> > >*, std::__1::vector<v8::Local<v8::Value>, std::__1::allocator<v8::Local<v8::Value> > >*)  (in node) + 110  [0x100cfb42e]
    +                 2848 v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*)  (in node) + 285  [0x100ece0ed]
    +                   2848 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*)  (in node) + 213  [0x100feeb95]
    +                     2848 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&)  (in node) + 2515  [0x100fef583]
    +                       2848 Builtins_JSEntry  (in node) + 131  [0x10172c4c3]
    +                         2848 Builtins_JSEntryTrampoline  (in node) + 91  [0x10172c73b]
    +                           2848 Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
    +                             2848 Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
    +                               2848 Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
    +                                 2848 Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
    +                                   2848 Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
    +                                     2848 Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
    +                                       2848 Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
    +                                         2848 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit  (in node) + 57  [0x10179afb9]
    +                                           2848 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*)  (in node) + 255  [0x100f19f8f]
    +                                             2848 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments)  (in node) + 550  [0x100f1a836]
    +                                               2848 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo)  (in node) + 462  [0x100f1b13e]
    +                                                 2848 void ivm::detail::RunBarrier<ivm::detail::CallbackMaker<v8::Local<v8::Value> (*)(ivm::IsolateHandle&), &(v8::Local<v8::Value> ivm::detail::unbind_member_function<v8::Local<v8::Value> (ivm::IsolateHandle::*)()>::invoke<&(ivm::IsolateHandle::Dispose())>(ivm::IsolateHandle&)), -1, v8::FunctionCallbackInfo<v8::Value> const&>::Callback(v8::FunctionCallbackInfo<v8::Value> const&)::'lambda'()>(&(ivm::IsolateHandle::Dispose()))  (in isolated_vm.node) + 27  [0x10da24c0b]
    +                                                   2848 void ivm::detail::CallbackMaker<v8::Local<v8::Value> (*)(ivm::IsolateHandle&), &(v8::Local<v8::Value> ivm::detail::unbind_member_function<v8::Local<v8::Value> (ivm::IsolateHandle::*)()>::invoke<&(ivm::IsolateHandle::Dispose())>(ivm::IsolateHandle&)), -1, v8::FunctionCallbackInfo<v8::Value> const&>::Spread<0ul>(v8::FunctionCallbackInfo<v8::Value> const&, std::__1::integer_sequence<unsigned long, 0ul>)::'lambda'()::operator()() const  (in isolated_vm.node) + 97  [0x10da24cf1]
    +                                                     2848 ivm::IsolateHandle::Dispose()  (in isolated_vm.node) + 20  [0x10da19e54]
    +                                                       2848 ivm::IsolateHolder::Dispose()  (in isolated_vm.node) + 60  [0x10d9f155c]
    +                                                         2848 ivm::IsolateEnvironment::Terminate()  (in isolated_vm.node) + 113  [0x10d9e7af1]
    +                                                           2848 ivm::Scheduler::CancelAsync()  (in isolated_vm.node) + 36  [0x10d9f4bf4]
    +                                                             2848 std::__1::mutex::lock()  (in libc++.1.dylib) + 9  [0x7fff204603d9]
    +                                                               2848 _pthread_mutex_firstfit_lock_slow  (in libsystem_pthread.dylib) + 204  [0x7fff204c5192]
    +                                                                 2848 _pthread_mutex_firstfit_lock_wait  (in libsystem_pthread.dylib) + 76  [0x7fff204c72ab]
    +                                                                   2848 __psynch_mutexwait  (in libsystem_kernel.dylib) + 10  [0x7fff204964ca]
    2848 Thread_118355833
    + 2848 thread_start  (in libsystem_pthread.dylib) + 15  [0x7fff204c5443]
    +   2848 _pthread_start  (in libsystem_pthread.dylib) + 224  [0x7fff204c98fc]
    +     2848 node::WorkerThreadsTaskRunner::DelayedTaskScheduler::Run()  (in node) + 361  [0x100da2529]
    +       2848 uv_run  (in node) + 401  [0x10170f901]
    +         2848 uv__io_poll  (in node) + 947  [0x101722b43]
    +           2848 kevent  (in libsystem_kernel.dylib) + 10  [0x7fff20498c4a]
    2848 Thread_118355834
    + 2848 thread_start  (in libsystem_pthread.dylib) + 15  [0x7fff204c5443]
    +   2848 _pthread_start  (in libsystem_pthread.dylib) + 224  [0x7fff204c98fc]
    +     2848 node::(anonymous namespace)::PlatformWorkerThread(void*)  (in node) + 339  [0x100d9f6f3]
    +       2848 node::TaskQueue<v8::Task>::BlockingPop()  (in node) + 72  [0x100da2738]
    +         2848 uv_cond_wait  (in node) + 9  [0x10171d449]
    +           2848 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1298  [0x7fff204c9e49]
    +             2848 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff20496cde]
    2848 Thread_118355835
    + 2848 thread_start  (in libsystem_pthread.dylib) + 15  [0x7fff204c5443]
    +   2848 _pthread_start  (in libsystem_pthread.dylib) + 224  [0x7fff204c98fc]
    +     2848 node::(anonymous namespace)::PlatformWorkerThread(void*)  (in node) + 339  [0x100d9f6f3]
    +       2848 node::TaskQueue<v8::Task>::BlockingPop()  (in node) + 72  [0x100da2738]
    +         2848 uv_cond_wait  (in node) + 9  [0x10171d449]
    +           2848 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1298  [0x7fff204c9e49]
    +             2848 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff20496cde]
    2848 Thread_118355836
    + 2848 thread_start  (in libsystem_pthread.dylib) + 15  [0x7fff204c5443]
    +   2848 _pthread_start  (in libsystem_pthread.dylib) + 224  [0x7fff204c98fc]
    +     2848 node::(anonymous namespace)::PlatformWorkerThread(void*)  (in node) + 339  [0x100d9f6f3]
    +       2848 node::TaskQueue<v8::Task>::BlockingPop()  (in node) + 72  [0x100da2738]
    +         2848 uv_cond_wait  (in node) + 9  [0x10171d449]
    +           2848 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1298  [0x7fff204c9e49]
    +             2848 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff20496cde]
    2848 Thread_118355837
    + 2848 thread_start  (in libsystem_pthread.dylib) + 15  [0x7fff204c5443]
    +   2848 _pthread_start  (in libsystem_pthread.dylib) + 224  [0x7fff204c98fc]
    +     2848 node::(anonymous namespace)::PlatformWorkerThread(void*)  (in node) + 339  [0x100d9f6f3]
    +       2848 node::TaskQueue<v8::Task>::BlockingPop()  (in node) + 72  [0x100da2738]
    +         2848 uv_cond_wait  (in node) + 9  [0x10171d449]
    +           2848 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1298  [0x7fff204c9e49]
    +             2848 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff20496cde]
    2848 Thread_118355838
    + 2848 thread_start  (in libsystem_pthread.dylib) + 15  [0x7fff204c5443]
    +   2848 _pthread_start  (in libsystem_pthread.dylib) + 224  [0x7fff204c98fc]
    +     2848 node::inspector::(anonymous namespace)::StartIoThreadMain(void*)  (in node) + 19  [0x100e10de3]
    +       2848 uv_sem_wait  (in node) + 16  [0x10171da50]
    +         2848 semaphore_wait_trap  (in libsystem_kernel.dylib) + 10  [0x7fff204942f6]
    2848 Thread_118355840
      2848 thread_start  (in libsystem_pthread.dylib) + 15  [0x7fff204c5443]
        2848 _pthread_start  (in libsystem_pthread.dylib) + 224  [0x7fff204c98fc]
          2848 void* std::__1::__thread_proxy<std::__1::tuple<std::__1::unique_ptr<std::__1::__thread_struct, std::__1::default_delete<std::__1::__thread_struct> >, ivm::thread_pool_t::new_thread(std::__1::lock_guard<std::__1::mutex>&)::$_1> >(void*)  (in isolated_vm.node) + 164  [0x10d9ff544]
            2848 ivm::IsolatedScheduler::SendWake()::$_2::__invoke(bool, void*)  (in isolated_vm.node) + 49  [0x10d9f5921]
              2848 ivm::IsolateEnvironment::AsyncEntry()  (in isolated_vm.node) + 2405  [0x10d9e8fa5]
                2848 ivm::ThreePhaseTask::Phase2Runner::Run()  (in isolated_vm.node) + 125  [0x10d9f8d3d]
                  2848 ivm::EvalRunner::Phase2()  (in isolated_vm.node) + 173  [0x10da081ad]
                    2848 v8::Local<v8::Value> ivm::RunWithTimeout<ivm::EvalRunner::Phase2()::'lambda0'()>(unsigned int, ivm::EvalRunner::Phase2()::'lambda0'()&&)  (in isolated_vm.node) + 427  [0x10da0945b]
                      2848 v8::Script::Run(v8::Local<v8::Context>)  (in node) + 645  [0x100eba8a5]
                        2848 v8::internal::Execution::Call(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*)  (in node) + 213  [0x100feeb95]
                          2848 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&)  (in node) + 2515  [0x100fef583]
                            2848 Builtins_JSEntry  (in node) + 131  [0x10172c4c3]
                              2848 Builtins_JSEntryTrampoline  (in node) + 91  [0x10172c73b]
                                2848 Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
                                  2848 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit  (in node) + 57  [0x10179afb9]
                                    2848 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*)  (in node) + 255  [0x100f19f8f]
                                      2848 v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments)  (in node) + 550  [0x100f1a836]
                                        2848 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo)  (in node) + 462  [0x100f1b13e]
                                          2848 void ivm::detail::RunBarrier<ivm::detail::CallbackMaker<v8::Local<v8::Value> (*)(ivm::ReferenceHandle&, v8::MaybeLocal<v8::Value>, v8::Maybe<ivm::ArrayRange>, v8::MaybeLocal<v8::Object>), &(v8::Local<v8::Value> ivm::detail::unbind_member_function<v8::Local<v8::Value> (ivm::ReferenceHandle::*)(v8::MaybeLocal<v8::Value>, v8::Maybe<ivm::ArrayRange>, v8::MaybeLocal<v8::Object>)>::invoke<&(v8::Local<v8::Value> ivm::ReferenceHandle::Apply<0>(v8::MaybeLocal<v8::Value>, v8::Maybe<ivm::ArrayRange>, v8::MaybeLocal<v8::Object>))>(ivm::ReferenceHandle&, v8::MaybeLocal<v8::Value>, v8::Maybe<ivm::ArrayRange>, v8::MaybeLocal<v8::Object>)), -1, v8::FunctionCallbackInfo<v8::Value> const&>::Callback(v8::FunctionCallbackInfo<v8::Value> const&)::'lambda'()>(0)  (in isolated_vm.node) + 27  [0x10da43ceb]
                                            2848 void ivm::detail::CallbackMaker<v8::Local<v8::Value> (*)(ivm::ReferenceHandle&, v8::MaybeLocal<v8::Value>, v8::Maybe<ivm::ArrayRange>, v8::MaybeLocal<v8::Object>), &(v8::Local<v8::Value> ivm::detail::unbind_member_function<v8::Local<v8::Value> (ivm::ReferenceHandle::*)(v8::MaybeLocal<v8::Value>, v8::Maybe<ivm::ArrayRange>, v8::MaybeLocal<v8::Object>)>::invoke<&(v8::Local<v8::Value> ivm::ReferenceHandle::Apply<0>(v8::MaybeLocal<v8::Value>, v8::Maybe<ivm::ArrayRange>, v8::MaybeLocal<v8::Object>))>(ivm::ReferenceHandle&, v8::MaybeLocal<v8::Value>, v8::Maybe<ivm::ArrayRange>, v8::MaybeLocal<v8::Object>)), -1, v8::FunctionCallbackInfo<v8::Value> const&>::Spread<0ul, 1ul, 2ul, 3ul>(v8::FunctionCallbackInfo<v8::Value> const&, std::__1::integer_sequence<unsigned long, 0ul, 1ul, 2ul, 3ul>)::'lambda'()::operator()() const  (in isolated_vm.node) + 524  [0x10da43f7c]
                                              2848 ivm::ThreePhaseTask::RunSync(ivm::IsolateHolder&, bool)  (in isolated_vm.node) + 494  [0x10d9f9b3e]
                                                2848 ivm::Scheduler::AsyncWait::Wait()  (in isolated_vm.node) + 78  [0x10d9f564e]
                                                  2848 std::__1::condition_variable::wait(std::__1::unique_lock<std::__1::mutex>&)  (in libc++.1.dylib) + 18  [0x7fff20432d72]
                                                    2848 _pthread_cond_wait  (in libsystem_pthread.dylib) + 1298  [0x7fff204c9e49]
                                                      2848 __psynch_cvwait  (in libsystem_kernel.dylib) + 10  [0x7fff20496cde]

Total number in stack (recursive counted multiple, when >=5):
        8       Builtins_InterpreterEntryTrampoline  (in node) + 202  [0x10172e52a]
        7       _pthread_start  (in libsystem_pthread.dylib) + 224  [0x7fff204c98fc]
        7       thread_start  (in libsystem_pthread.dylib) + 15  [0x7fff204c5443]
        5       __psynch_cvwait  (in libsystem_kernel.dylib) + 0  [0x7fff20496cd4]
        5       _pthread_cond_wait  (in libsystem_pthread.dylib) + 1298  [0x7fff204c9e49]

Sort by top of stack, same collapsed (when >= 5):
        __psynch_cvwait  (in libsystem_kernel.dylib)        14240
        __psynch_mutexwait  (in libsystem_kernel.dylib)        2848
        kevent  (in libsystem_kernel.dylib)        2848
        semaphore_wait_trap  (in libsystem_kernel.dylib)        2848

Binary Images:
       0x100c64000 -        0x1044847af +node (0) <F4C5F2BC-ACCE-3125-90F8-2BA377D87BBD> /Users/*/node
       0x10d9de000 -        0x10da69ff7 +isolated_vm.node (0) <C0938873-7E34-319D-AF43-A62488BA1B74> /Users/*/isolated_vm.node
       0x10f10d000 -        0x10f1a768f  dyld (852.2) <0CC19410-FD43-39AE-A32A-50273F8303A4> /usr/lib/dyld
    0x7fff20201000 -     0x7fff20202e7f  libsystem_blocks.dylib (79) <925E3B6D-184D-3E73-97B1-643C4ADB387A> /usr/lib/system/libsystem_blocks.dylib
    0x7fff20203000 -     0x7fff20238bcf  libxpc.dylib (2038.120.1) <FFFB49D7-2CA6-3E1F-AE4E-5697B19B7D76> /usr/lib/system/libxpc.dylib
    0x7fff20239000 -     0x7fff20250b8f  libsystem_trace.dylib (1277.120.1) <7E800ECA-DFDB-3737-A3C5-FFDE37E65383> /usr/lib/system/libsystem_trace.dylib
    0x7fff20251000 -     0x7fff202eefdf  libcorecrypto.dylib (1000.140.4) <D211160D-E22F-3440-8054-1F5824519C7F> /usr/lib/system/libcorecrypto.dylib
    0x7fff202ef000 -     0x7fff2031bff7  libsystem_malloc.dylib (317.140.5) <050E37E1-1458-3F80-BFA3-F1488570169D> /usr/lib/system/libsystem_malloc.dylib
    0x7fff2031c000 -     0x7fff2036080f  libdispatch.dylib (1271.120.2) <8144B0BD-90D2-3EAE-999F-AB0D14082088> /usr/lib/system/libdispatch.dylib
    0x7fff20361000 -     0x7fff2039aad7  libobjc.A.dylib (824) <8C7C49A1-4211-3E4C-BA3D-160D675EEE96> /usr/lib/libobjc.A.dylib
    0x7fff2039b000 -     0x7fff2039dff7  libsystem_featureflags.dylib (28.60.1) <E5C43AE3-19E7-3DAB-8B5D-D79A4B68B5C0> /usr/lib/system/libsystem_featureflags.dylib
    0x7fff2039e000 -     0x7fff20426ff7  libsystem_c.dylib (1439.141.1) <3C273899-4CBE-32D5-BB31-7A449743204F> /usr/lib/system/libsystem_c.dylib
    0x7fff20427000 -     0x7fff2047cff7  libc++.1.dylib (905.6) <FD6DB1CB-B14B-3404-8BEB-B459C2F6C303> /usr/lib/libc++.1.dylib
    0x7fff2047d000 -     0x7fff20492ff7  libc++abi.dylib (905.6) <D0CDDF98-1C04-300F-B685-4A4C59C04C42> /usr/lib/libc++abi.dylib
    0x7fff20493000 -     0x7fff204c2fff  libsystem_kernel.dylib (7195.141.6) <78289AAE-61B5-339F-A485-8819BC2388F2> /usr/lib/system/libsystem_kernel.dylib
    0x7fff204c3000 -     0x7fff204cefff  libsystem_pthread.dylib (454.120.2) <1268FF2D-A513-3B51-BA65-AF2FF5789DDB> /usr/lib/system/libsystem_pthread.dylib
    0x7fff204cf000 -     0x7fff2050aff7  libdyld.dylib (852.2) <3DE0178A-0AEE-3D08-AE19-6C6403F69BA1> /usr/lib/system/libdyld.dylib
    0x7fff2050b000 -     0x7fff20514fef  libsystem_platform.dylib (254.80.2) <EF52D569-09F5-32E1-B1B3-34E2CA55A017> /usr/lib/system/libsystem_platform.dylib
    0x7fff20515000 -     0x7fff20540fff  libsystem_info.dylib (542.40.3) <55B39B7F-957B-3D99-A8DF-7CA80D38155D> /usr/lib/system/libsystem_info.dylib
    0x7fff20541000 -     0x7fff209de3df  com.apple.CoreFoundation (6.9 - 1778.101) <8CF9D741-ADFF-3D5E-ACDE-DC342701EE0D> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
    0x7fff226b0000 -     0x7fff2290fff7  libicucore.A.dylib (66112) <AC994BC1-F9CC-359C-A7B5-F2821EAEF650> /usr/lib/libicucore.A.dylib
    0x7fff22910000 -     0x7fff22919fff  libsystem_darwin.dylib (1439.141.1) <2C81A009-45BB-30D7-A4F7-4B2EEC691617> /usr/lib/system/libsystem_darwin.dylib
    0x7fff22d2f000 -     0x7fff22d3aff3  libsystem_notify.dylib (279.40.4) <2E40EA4A-B124-3010-8379-1B4D7082A08F> /usr/lib/system/libsystem_notify.dylib
    0x7fff24cc7000 -     0x7fff24cd5ff7  libsystem_networkextension.dylib (1295.140.3) <83AA4425-2F1D-36EC-B77B-8D4F03CDDB68> /usr/lib/system/libsystem_networkextension.dylib
    0x7fff24d34000 -     0x7fff24d4affb  libsystem_asl.dylib (385) <8D324D65-EE16-3A1A-BD39-ACB1B3050D1F> /usr/lib/system/libsystem_asl.dylib
    0x7fff26411000 -     0x7fff26418ffb  libsystem_symptoms.dylib (1431.140.1) <1B4D8837-C951-3B69-B079-85D477749E8B> /usr/lib/system/libsystem_symptoms.dylib
    0x7fff28420000 -     0x7fff28430ff3  libsystem_containermanager.dylib (318.100.4) <1139CD47-9CBA-356F-8694-1D00EB9F0C8F> /usr/lib/system/libsystem_containermanager.dylib
    0x7fff29134000 -     0x7fff29137ffb  libsystem_configuration.dylib (1109.140.1) <02F3A5C9-6289-3012-8F5F-F1DB669ADB79> /usr/lib/system/libsystem_configuration.dylib
    0x7fff29138000 -     0x7fff2913cfff  libsystem_sandbox.dylib (1441.141.4) <5471601B-5072-3E97-8926-804FF08DC4C0> /usr/lib/system/libsystem_sandbox.dylib
    0x7fff29e2e000 -     0x7fff29e30ff3  libquarantine.dylib (119.40.2) <3244B57B-9FDF-373E-9F96-A7BAD7534F23> /usr/lib/system/libquarantine.dylib
    0x7fff2a3d9000 -     0x7fff2a3ddfff  libsystem_coreservices.dylib (127.1) <619CCB6D-226C-35BD-98FB-04A18FD54792> /usr/lib/system/libsystem_coreservices.dylib
    0x7fff2a5ed000 -     0x7fff2a634fff  libsystem_m.dylib (3186.100.3) <D61B56FE-649B-34A0-8446-25685B2BBBF2> /usr/lib/system/libsystem_m.dylib
    0x7fff2a636000 -     0x7fff2a63bfff  libmacho.dylib (980) <A4F4D532-7824-3E4E-8FB6-45617415E7DD> /usr/lib/system/libmacho.dylib
    0x7fff2a658000 -     0x7fff2a663fff  libcommonCrypto.dylib (60178.120.3) <CF1E0E70-9F6C-3FAF-82B2-D55F7C9EBB03> /usr/lib/system/libcommonCrypto.dylib
    0x7fff2a664000 -     0x7fff2a66eff7  libunwind.dylib (201) <4602E909-C71A-3006-8140-BE616DA241EE> /usr/lib/system/libunwind.dylib
    0x7fff2a66f000 -     0x7fff2a676fff  liboah.dylib (203.58) <F72C2D50-7279-3497-8A59-56908F9661F3> /usr/lib/liboah.dylib
    0x7fff2a677000 -     0x7fff2a681ff7  libcopyfile.dylib (173.40.2) <B0F35A80-D5E3-33DD-A47D-ACBFE1300523> /usr/lib/system/libcopyfile.dylib
    0x7fff2a682000 -     0x7fff2a689fff  libcompiler_rt.dylib (102.2) <1C049207-1719-39AC-A2A9-6E5BE28AA138> /usr/lib/system/libcompiler_rt.dylib
    0x7fff2a68a000 -     0x7fff2a68cff7  libsystem_collections.dylib (1439.141.1) <F2D775D9-AAEF-371F-AA54-CFB882B9B430> /usr/lib/system/libsystem_collections.dylib
    0x7fff2a68d000 -     0x7fff2a68ffff  libsystem_secinit.dylib (87.60.1) <EB4516ED-1F8B-3E8A-8C4B-B209A33DCCEF> /usr/lib/system/libsystem_secinit.dylib
    0x7fff2a690000 -     0x7fff2a692ff7  libremovefile.dylib (49.120.1) <1AEE3D84-32F9-35FB-8036-B178C9E27D20> /usr/lib/system/libremovefile.dylib
    0x7fff2a693000 -     0x7fff2a693ffb  libkeymgr.dylib (31) <698AF6EE-08BB-36CF-B7AD-9EC16E36FA0B> /usr/lib/system/libkeymgr.dylib
    0x7fff2a694000 -     0x7fff2a69bff3  libsystem_dnssd.dylib (1310.140.1) <0685BDB0-9A98-3ADD-B95A-11F221FD80D7> /usr/lib/system/libsystem_dnssd.dylib
    0x7fff2a69c000 -     0x7fff2a6a1ff3  libcache.dylib (83) <B51FAB34-AA9C-38C5-95F1-E5E54B21EA67> /usr/lib/system/libcache.dylib
    0x7fff2a6a2000 -     0x7fff2a6a3ff7  libSystem.B.dylib (1292.120.1) <DBD0A184-CD98-3225-8E9B-D5BFE0D30562> /usr/lib/libSystem.B.dylib
    0x7fff2a6a4000 -     0x7fff2a6a7ff7  libfakelink.dylib (3) <BE0E6C60-675A-3739-A47A-67C650B1F790> /usr/lib/libfakelink.dylib
    0x7fff2a6a8000 -     0x7fff2a6a8ff7  com.apple.SoftLinking (1.0 - 1) <9E4B6591-74E3-3B36-91C4-851FAA567DAA> /System/Library/PrivateFrameworks/SoftLinking.framework/Versions/A/SoftLinking
    0x7fff2daa6000 -     0x7fff2daa6ff7  liblaunch.dylib (2038.120.1) <4A353070-A560-3A98-8869-28C92435C6B2> /usr/lib/system/liblaunch.dylib
    0x7fff2ff3d000 -     0x7fff2ff3dfff  libsystem_product_info_filter.dylib (8.40.1) <78928329-DD98-3799-989D-870DF92FE8D5> /usr/lib/system/libsystem_product_info_filter.dylib
Sample analysis of process 23338 written to file /dev/stdout
@marcusdarmstrong
Copy link
Author

Further testing has caused me to realize I was entirely mistaken when thinking this was related to promises. In fact, it appears to be due to isolate disposal while there's a scheduled async task that interacts synchronously with the main isolate:

const ivm = require('isolated-vm');

setInterval(() => { console.log("Event Loop is running"); }, 100);

(async () => {
  const isolate = new ivm.Isolate();
  const context = isolate.createContextSync();
  context.global.setSync("getProm", () => {}, { reference: true });
  context.eval("getProm.applySync()"); // Awaiting here resolves the issue
  context.release();
  console.log(`Context for Isolate released`);
  isolate.dispose();
  console.log(`Isolate disposed`);
})();

@laverdet
Copy link
Owner

laverdet commented May 3, 2022

Thanks for the short test case. The fix for this is out on npm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants