sdk icon indicating copy to clipboard operation
sdk copied to clipboard

[vm/ffi] Calling `NativeCallable.listener` from a `NativeFinalizer` callback

Open dcharkes opened this issue 1 year ago • 0 comments

Currently, calling a NativeCallable.listener from a NativeFinalizer callback hits an assert:

../../runtime/vm/runtime_entry.cc: 4040: error: expected: current_thread->execution_state() == Thread::kThreadInNative

https://github.com/dart-lang/sdk/blob/1e0223e6d839255d18c8940a083482237f5f9318/runtime/vm/runtime_entry.cc#L4037-L4043

The assumption is that if we have a current thread, it must be in native code. However, when the NativeCallable.listener is called from a finalizer callback, we have a current thread, but it is in the VM.

Repro: https://github.com/dart-lang/native/tree/native-finalizer/pkgs/native_assets_cli/example/native_add_library

@liamappelbe Could you please take a look at supporting this use case?

cc @mkustermann

dcharkes avatar Feb 16 '24 09:02 dcharkes