-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Not safe to call Dart_DeleteWeakPersistentHandle_DL during finalisation callback #48321
Comments
Another solution would be to make it legal to call |
Just so it is more clear what is the issue, here is a sample code. //dart code
void main(List<String> arguments) {
var obj = Object();
createWeakHandle(obj);
} //c code
Dart_WeakPersistentHandle myhandle;
void handle_finalizer(void* isolate_callback_data, void* somePrt) {
Dart_DeleteWeakPersistentHandle_DL(myhandle);
}
void createWeakHandle(Dart_Handle handle) {
myhandle = Dart_NewWeakPersistentHandle_DL(handle, somePrt, size, handle_finalizer);
}
This will result in a crash on main method exit. This is also the same for I believe |
This is indeed not the behavior. I'm only deleting handles when the isolate is not shutting down in that CL: https://dart-review.googlesource.com/c/sdk/+/229544/11/runtime/lib/finalizer.cc#69 |
Can you share a bit about the status of this? |
@dcharkes @mkustermann I think we need to fix this API, because it makes it somewhat complicated to use. As a temporary work-around we could expose Dart_CurrentIsolateGroup through the DL API - but maybe we should change shutdown process in a way that deleting handles becomes safe - so that users would not need to include checks in their own code. WDYT? |
We would really appreciate that, even if it is just exposing Right now we are using an ugly hack that is based on the fact that
Obviously we would like to avoid that. |
The concept of an isolate group doesn't exist on its own. It is created internally with the first isolate and deleted internally when the last isolate dies. So I don't think exposing it through the API is a very good idea.
My suggestion would be to perform finalization of persistent/weak-persistent handles with a valid isolate group, before triggering the isolate group shutdown itself. e.g. right here in runtime/vm/isolate.cc const bool shutdown_group =
isolate_group->UnregisterIsolateDecrementCount(isolate);
if (shutdown_group) {
...
Thread::EnterIsolateGroupAsHelper(isolate_group, Thread::kUnknownTask, /*bypass_safepoint=*/false);
BackgroundCompiler::Stop(isolate_group);
Thread::ExitIsolateGroupAsHelper(/*bypass_safepoint=*/false);
...
} |
/cc @aam Interested in looking at this? |
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
…ue on isolate shutdown: dart-lang/sdk#48321
According to the documentation on
Dart_NewWeakPersistentHandle
whenever the finalizer callback is called, then:but in my tests this is not the case, when the finalization is done during shutdown of the isolate. The situations is complicated by the fact that
Dart_CurrentIsolateGroup
is not exposed in the_DL
API.Here is an example stack trace:
Obviously it is not needed to call
Dart_DeleteWeakPersistentHandle
during shutdown the isolate, since the lifetime is tied to the same, but how do I as a user distinguish this from the situation where the associatedDart_Handle
has been garbage collected?Could you expose
Dart_CurrentIsolateGroup
asDart_CurrentIsolateGroup_DL
so we can check, if it is safe to callDart_DeleteWeakPersistentHandle
.The text was updated successfully, but these errors were encountered: