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

Conversation

@jason-simmons
Copy link
Member

@jason-simmons jason-simmons commented Jun 14, 2019

Applications can use an embedder API to obtain the isolate ID and then use it in calls to the Dart service protocol.

@tvolkert
Copy link
Contributor

Just curious: is this to enable Espresso's use case?

/cc @goderbauer

@jason-simmons
Copy link
Member Author

Yes - this was requested by Espresso

Copy link
Contributor

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

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

This is susceptible to racy behavior when it comes to isolate initialization across threads as well the consumption of the isolate ID in Dart code on isolate launch.

I suggest using the root isolate create callback to fire the request to fetch the ID from Dart code and have the caller in Dart install a watcher. Also, please wire up a unit test in shell_unittests. I believe the fixtures necessary to test this are already in place.

* in queries to the Dart service protocol.
*/
public String getIsolateServiceId() {
return isolateServiceId;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is racy. How is the caller going to know to wait for the isolate launch to be completed?

Copy link
Member Author

Choose a reason for hiding this comment

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

With a getter API the client would need to poll until the isolate ID is available, or otherwise wait for another signal of app liveness such as the first frame callback. I'll add a callback specifically for the isolate ID.

public DartExecutor(@NonNull FlutterJNI flutterJNI) {
this.flutterJNI = flutterJNI;
this.messenger = new DartMessenger(flutterJNI);
messenger.setMessageHandler("flutter/isolate", isolateChannelMessageHandler);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is racy to changes in the engine that affect isolate initialization. This executor is initialized on the platform thread while the engine is racing to creating the isolate on the UI thread. It the engine wins, the message get dropped on the floor.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure I understand the concern here. In the embedder DartExecutor will be created and the message handler will be installed at FlutterNativeView/FlutterEngine construction time. This will happen before the app can call runBundle and start the isolate.

(Note that the message containing the isolate ID is being sent to the platform host side, not to Dart code)

return isolateServiceId;
}

private BinaryMessenger.BinaryMessageHandler isolateChannelMessageHandler =
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you mind moving this up in between the field declarations and the constructor declaration? And can you mark this as final?

Copy link
Member Author

Choose a reason for hiding this comment

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

done

new BinaryMessenger.BinaryMessageHandler() {
@Override
public void onMessage(ByteBuffer message, final BinaryReply callback) {
isolateServiceId = StringCodec.INSTANCE.decodeMessage(message);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we need a listener for this? The value is not available immediately upon construction, but instead appears an unknown time later. I'm not sure how clients will know, in general, when they can query this...but I can always add that later if we're not sure if we need it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a listener interface

Copy link
Contributor

@matthew-carroll matthew-carroll left a comment

Choose a reason for hiding this comment

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

Thanks for putting this together.

Applications can use an embedder API to obtain the isolate ID and then use it
in calls to the Dart service protocol.
@jason-simmons
Copy link
Member Author

Added an embedder unit test - PTAL

@jason-simmons jason-simmons merged commit ea7ca98 into flutter:master Jun 17, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 18, 2019
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Jun 18, 2019
flutter/engine@20d3861...05c034e

git log 20d3861..05c034e --no-merges --oneline
05c034e Update component manifests for ambient replace-as-executable (flutter/engine#9350)
66022ce Roll src/third_party/skia 55091020435c..4b203ad7ac02 (6 commits) (flutter/engine#9352)
fcff2d6 Use the DartServiceIsolate status callback to publish the observatory URI to the Android embedder (flutter/engine#9337)
ea7ca98 Send the isolate service ID from the engine to the embedder (flutter/engine#9324)
675033f Check for invalid indexes when performing InputAdpator backspace. (flutter/engine#9322)
e5918d1 Roll src/third_party/skia 92b81e14d9c2..55091020435c (6 commits) (flutter/engine#9348)
e00ac47 Reorganize darwin for shared ios/macOS (flutter/engine#9255)
9da409c Fix crash on Huawei device with AndroidView (flutter/engine#9192)
a0f8554 Removed an unused class definition for iOS code. (flutter/engine#9346)
96a1a84 Replace lock_guard with scoped_lock and use class template argument deduction. (flutter/engine#9338)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (liyuqian@google.com), and stop
the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 19, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 19, 2019
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
flutter/engine@20d3861...05c034e

git log 20d3861..05c034e --no-merges --oneline
05c034e Update component manifests for ambient replace-as-executable (flutter/engine#9350)
66022ce Roll src/third_party/skia 55091020435c..4b203ad7ac02 (6 commits) (flutter/engine#9352)
fcff2d6 Use the DartServiceIsolate status callback to publish the observatory URI to the Android embedder (flutter/engine#9337)
ea7ca98 Send the isolate service ID from the engine to the embedder (flutter/engine#9324)
675033f Check for invalid indexes when performing InputAdpator backspace. (flutter/engine#9322)
e5918d1 Roll src/third_party/skia 92b81e14d9c2..55091020435c (6 commits) (flutter/engine#9348)
e00ac47 Reorganize darwin for shared ios/macOS (flutter/engine#9255)
9da409c Fix crash on Huawei device with AndroidView (flutter/engine#9192)
a0f8554 Removed an unused class definition for iOS code. (flutter/engine#9346)
96a1a84 Replace lock_guard with scoped_lock and use class template argument deduction. (flutter/engine#9338)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff (liyuqian@google.com), and stop
the roller if necessary.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants