Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

chinmaygarde
Copy link
Member

In #19843, a regression was introduced
where an image descriptor object that has a Dart peer could be collected on a
concurrent task runner thread. Collection of such object needs to enter isolate
scope which might still be active on the UI thread. A comment in the original
commit explicitly mentions
this and attempts to achieve the collection of the
Dart wrappable on the UI task runner. However, the author missed that the object
was present in the captures of a copyable closure. These captures may be
released on any of the participating threads. To avoid the the indeterminism of
the smart pointer being dropped on the concurrent task runner thread, this patch
resorts to manually reference counting the descriptor.

Fixes flutter/flutter#72144

…that cross thread-boundaries.

In flutter#19843, a regression was introduced
where an image descriptor object that has a Dart peer could be collected on a
concurrent task runner thread. Collection of such object needs to enter isolate
scope which might still be active on the UI thread. [A comment in the original
commit explicitly mentions][1] this and attempts to achieve the collection of the
Dart wrappable on the UI task runner. However, the author missed that the object
was present in the captures of a copyable closure. These captures may be
released on any of the participating threads. To avoid the the indeterminism of
the smart pointer being dropped on the concurrent task runner thread, this patch
resorts to manually reference counting the descriptor.

Fixes flutter/flutter#72144

[1]: https://github.com/flutter/engine/pull/19843/files#diff-a3034d4a06133381b6b636d841ec98cb7cfce640f316dda9e71eda4d9e7872f6R227
// `ImageDecoder::Decode` itself is invoked on the UI thread, so the
// collection of the smart pointer from which we obtained the raw descriptor
// is fine in this scope.
auto raw_descriptor = descriptor_ref_ptr.get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to add a method to fml::RefPtr that detaches the raw pointer from the RefPtr and gives the caller ownership of the ref count that was held by the RefPtr.

(similar to std::unique_ptr::release or Skia's sk_sp::release)

@chinmaygarde
Copy link
Member Author

Filed a flake report and re-run the presubmit.

@chinmaygarde chinmaygarde added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jan 7, 2021
@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite build_and_test_linux_unopt_debug has failed. Please fix the issues identified (or deflake) before re-applying this label.

@fluttergithubbot fluttergithubbot removed the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jan 7, 2021
@chinmaygarde chinmaygarde added the waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land. label Jan 9, 2021
@fluttergithubbot fluttergithubbot merged commit cb2a81e into flutter:master Jan 9, 2021
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jan 9, 2021
@ftognetto
Copy link

Hello, is this in beta at the moment?

@chinmaygarde chinmaygarde deleted the descriptor_mutator branch July 7, 2022 22:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes waiting for tree to go green This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enter Isolate : Multiple mutators entering an isolate / Dart VM is shutting down
4 participants