node icon indicating copy to clipboard operation
node copied to clipboard

Crash during ThreadSafeFunction finalization

Open stefandtu opened this issue 1 year ago • 4 comments

Version

v.18.15.0

Platform

all (Win, MacOs)

Subsystem

node api

What steps will reproduce the bug?

electron_test_tsfn_node_integrated_mode.zip electrone_25_crash_tsfn

Close app window or press "Release" button

How often does it reproduce? Is there a required condition?

electron_node.log

[pid 628060, tid: 707296 ] --------------FreeEnvironment start : 000008820120C000 uv_loop: 00007FF740548E28 [pid 628060, tid: 707296 ] --------------FreeEnvironment set_stopping(true): 000008820120C000 [pid 628060, tid: 707296 ] --------------FreeEnvironment before RunCleanup : 000008820120C000 // Here, the released function is being finalized from a foreign context [pid 628060, tid: 707296 ] ThreadSafeFunction Finalize() f_name: test_tsfn Environment* :0000088200A9C000 Isolate: 0000088200834000 this=0000088200A7D400 [pid 628060, tid: 707296 ] env (param): 0000088200A9C000 env isolate ( env->isolate() ) : 0000088200834000 isolate to env ( Environment::GetCurrent(env->isolate()) ) : 000008820120C000 !!! Critical error Environment::GetCurrent(env->isolate()) not eq to env 0000088200A9C000 != 000008820120C000 .....

What is the expected behavior? Why is that the expected behavior?

No response

What do you see instead?

Absence of process abort

Additional information

My quick bug fix: /main/src/node_api.cc

void Finalize() {

v8::HandleScope scope(env->isolate); 
// <==  fix
v8::Context::Scope context_scope(env->context());    
// => fix
if (finalize_cb) {
  CallbackScope cb_scope(this);
  env->CallFinalizer<false>(finalize_cb, finalize_data, context);
}
EmptyQueueAndDelete();

}

stefandtu avatar Aug 14 '23 15:08 stefandtu