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

Fix navigation message relay. #20193

Merged
merged 2 commits into from
Aug 2, 2020
Merged

Fix navigation message relay. #20193

merged 2 commits into from
Aug 2, 2020

Conversation

mehmetf
Copy link
Contributor

@mehmetf mehmetf commented Aug 1, 2020

Partially reverts the change done in #19981 to make sure back button works on Android. There's a problem with std::move which already existed in the old code if DispatchPlatformMessage returns false. Fixing that is out of scope for this PR. It would also be good to add tests for navigation channel.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@mehmetf mehmetf requested a review from gaaclarke August 1, 2020 15:46
@auto-assign auto-assign bot requested a review from flar August 1, 2020 15:47
@mehmetf
Copy link
Contributor Author

mehmetf commented Aug 1, 2020

Fixing that is out of scope for this PR.

Apparently it has to be in scope since clang-tidy is not letting me submit this. I'll attempt.

@mehmetf
Copy link
Contributor Author

mehmetf commented Aug 1, 2020

I think this should make clang-tidy happy and match the old behavior.

@@ -303,7 +303,8 @@ void Engine::DispatchPlatformMessage(fml::RefPtr<PlatformMessage> message) {
} else if (channel == kSettingsChannel) {
HandleSettingsPlatformMessage(message.get());
return;
} else if (channel == kNavigationChannel) {
} else if (!runtime_controller_->IsRootIsolateRunning() &&
channel == kNavigationChannel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not move it back to where it was before (after the runtime_controller handling at 313-316) rather than add additional conditionals which make assumptions about the flow? If this is simply to "undo" the mistake in the previous fix then it should conform to the code before the fix as much as possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I looked at the first commit and see the problem with the std::move() now. Looking more at the flow to see how the new proposed logic applies...

Copy link
Contributor

Choose a reason for hiding this comment

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

It appears that the design issue here is that we have a method runtime_controller_->DispatchPlatformMessage that takes a shared pointer and may or may not consumer it as a result of its operation. We should not be giving it our only valid reference to that message if it may decide not to consume it.

Moving the most visible part of the conditional up to this else if clause solves only half of the problem because all we've really double checked is our half of the tests to see if the message is dispatchable by the runtime controller. The actual Dispatch method tests other conditions.

What about moving this message handling clause to after the runtime_controller gets a shot at it, but not using std::move so that we don't fumble the reference if the dispatch fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to fix this asap because it is a P0 regression so I wanted this revert to be as trivial as possible. I would like to revert the whole PR but then I would have to turn off the clang-tidy checks and I was trying to work around that.

I am not a C++ programmer. What would calling std::move twice on the same pointer do? I assume that's bad so I also assumed DispatchPlatformMessage rarely (if ever) returned false for a navigation message. Therefore, this new code is equivalent since HandleNavigationPlatformMessage only gets called if !runtime_controller_->IsRootIsolateRunning(); just like before.

What about moving this message handling clause to after the runtime_controller gets a shot at it, but not using std::move so that we don't fumble the reference if the dispatch fails?

I wasn't sure whether I can continue using the reference after std::move was called on it.

Copy link
Member

Choose a reason for hiding this comment

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

I think the logic in this PR is correct, and IMHO it's clearer than the previous implementation.

Most messages are passed to DispatchPlatformMessage, which relays the message to a handler implemented in Dart. However, there are some special message channels where the engine itself handles the message.

If the Dart isolate is not yet running, then the navigation channel will be processed within the engine so it can capture the initial route. I think it makes sense to separate that out as a special case alongside the other channels that are handled by the engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @jason-simmons . If you LGTM, I can submit :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

That make sense, but there is another condition inside the Dispatch method which means it might not be dispatched anyway, so technically this new logic is not the same as before. I'll leave it to Jason to LGTM it.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand how Refs interact with std::move(), can't this also be solved by moving the code back to where it was and removing the std::move() from the call to DispatchPlatformMessage? I believe the move in that case is just an optimization for "I no longer need this reference any more so rather than ref-counting the handoff here, just take mine" and by removing the move() we add a simple refcount logic so that DPM can be as conditional as it wants as to whether it uses the reference without affecting the validity of the original reference held in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @flar. I think that's a more disruptive change (but could be the right change). Ideally, I can submit this to solve the immediate problem and someone else can take a second pass to fix it + add a test for it.

You are right that this is not exactly the same logic as before but as I explained, it comes pretty close without having to disable the clang-tidy checks. I agree that it is probably not the right (long-term) change.

@mehmetf mehmetf merged commit 908fe01 into flutter:master Aug 2, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 3, 2020
zanderso pushed a commit to flutter/flutter that referenced this pull request Aug 3, 2020
* 7f5d044 Wait before switching surfaces (flutter/engine#20100)

* 5513273 Reland: Avoid a copy in EncodeImage (flutter/engine#20003)

* 1efdd95 Roll Dart SDK from bd528bfbd69d to ea6bde577d1c (19 revisions) (flutter/engine#20172)

* 3b0e697 Roll Skia from 8cc118dce813 to c3794dd52778 (27 revisions) (flutter/engine#20173)

* cb1a374 Roll Fuchsia Mac SDK from T2xc0OuiK... to i0zTcQ8Qb... (flutter/engine#20175)

* ed36b1a Roll Skia from c3794dd52778 to 2d01ed94605a (10 revisions) (flutter/engine#20179)

* fcc1eaf Fix iOS Keyboard stuck as UIKeyboardTypeNamePhonePad (flutter/engine#20181)

* 9c6837c Roll Skia from 2d01ed94605a to 7225788b9070 (6 revisions) (flutter/engine#20183)

* 13e993e Fix Typos (flutter/engine#19691)

* 98cfd1d Move platform specific information to `PlatformConfiguration` class (flutter/engine#19652)

* 22fb58b update nullability of drawAtlas methods and flesh out docs (flutter/engine#20176)

* bcc43df Roll Dart SDK from ea6bde577d1c to 033a81d924b9 (23 revisions) (flutter/engine#20186)

* cb4bb93 [web] increase number of shards. sync engine web tests same as flutter repo (flutter/engine#20164)

* d986b8d Enable linting in several files (flutter/engine#20134)

* 7dd092d Enable more linting (flutter/engine#20187)

* 3cc86ac Roll Dart SDK from 033a81d924b9 to ad5bcf16f1c8 (9 revisions) (flutter/engine#20191)

* 5ca8a2a Roll Dart SDK from ad5bcf16f1c8 to d169af6f7d8f (1 revision) (flutter/engine#20192)

* 4de0c04 Roll Dart SDK from d169af6f7d8f to 7e6c55e3aaf5 (1 revision) (flutter/engine#20196)

* 908fe01 Fix navigation message relay. (flutter/engine#20193)

* f1b3b69 Roll Dart SDK from 7e6c55e3aaf5 to 365525432a70 (2 revisions) (flutter/engine#20197)

* 8fbdd3f Fix parameter names

* 083282e Fix Implments typo
@gaaclarke
Copy link
Member

Man, that was nasty. The fix looks good to me. It's a bit concerning because there is still no test that asserts that it is correct.

I knew i was accepting a change in order with the memory fix but didn't consider that the logic was built around the assumption that a bool returning function always returns one value... nasty.

I can take a look into adding a test later today. Thanks @mehmetf.

@gaaclarke gaaclarke mentioned this pull request Aug 4, 2020
12 tasks
Pragya007 pushed a commit to Pragya007/flutter that referenced this pull request Aug 11, 2020
* 7f5d044 Wait before switching surfaces (flutter/engine#20100)

* 5513273 Reland: Avoid a copy in EncodeImage (flutter/engine#20003)

* 1efdd95 Roll Dart SDK from bd528bfbd69d to ea6bde577d1c (19 revisions) (flutter/engine#20172)

* 3b0e697 Roll Skia from 8cc118dce813 to c3794dd52778 (27 revisions) (flutter/engine#20173)

* cb1a374 Roll Fuchsia Mac SDK from T2xc0OuiK... to i0zTcQ8Qb... (flutter/engine#20175)

* ed36b1a Roll Skia from c3794dd52778 to 2d01ed94605a (10 revisions) (flutter/engine#20179)

* fcc1eaf Fix iOS Keyboard stuck as UIKeyboardTypeNamePhonePad (flutter/engine#20181)

* 9c6837c Roll Skia from 2d01ed94605a to 7225788b9070 (6 revisions) (flutter/engine#20183)

* 13e993e Fix Typos (flutter/engine#19691)

* 98cfd1d Move platform specific information to `PlatformConfiguration` class (flutter/engine#19652)

* 22fb58b update nullability of drawAtlas methods and flesh out docs (flutter/engine#20176)

* bcc43df Roll Dart SDK from ea6bde577d1c to 033a81d924b9 (23 revisions) (flutter/engine#20186)

* cb4bb93 [web] increase number of shards. sync engine web tests same as flutter repo (flutter/engine#20164)

* d986b8d Enable linting in several files (flutter/engine#20134)

* 7dd092d Enable more linting (flutter/engine#20187)

* 3cc86ac Roll Dart SDK from 033a81d924b9 to ad5bcf16f1c8 (9 revisions) (flutter/engine#20191)

* 5ca8a2a Roll Dart SDK from ad5bcf16f1c8 to d169af6f7d8f (1 revision) (flutter/engine#20192)

* 4de0c04 Roll Dart SDK from d169af6f7d8f to 7e6c55e3aaf5 (1 revision) (flutter/engine#20196)

* 908fe01 Fix navigation message relay. (flutter/engine#20193)

* f1b3b69 Roll Dart SDK from 7e6c55e3aaf5 to 365525432a70 (2 revisions) (flutter/engine#20197)

* 8fbdd3f Fix parameter names

* 083282e Fix Implments typo
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
* 7f5d044 Wait before switching surfaces (flutter/engine#20100)

* 5513273 Reland: Avoid a copy in EncodeImage (flutter/engine#20003)

* 1efdd95 Roll Dart SDK from bd528bfbd69d to ea6bde577d1c (19 revisions) (flutter/engine#20172)

* 3b0e697 Roll Skia from 8cc118dce813 to c3794dd52778 (27 revisions) (flutter/engine#20173)

* cb1a374 Roll Fuchsia Mac SDK from T2xc0OuiK... to i0zTcQ8Qb... (flutter/engine#20175)

* ed36b1a Roll Skia from c3794dd52778 to 2d01ed94605a (10 revisions) (flutter/engine#20179)

* fcc1eaf Fix iOS Keyboard stuck as UIKeyboardTypeNamePhonePad (flutter/engine#20181)

* 9c6837c Roll Skia from 2d01ed94605a to 7225788b9070 (6 revisions) (flutter/engine#20183)

* 13e993e Fix Typos (flutter/engine#19691)

* 98cfd1d Move platform specific information to `PlatformConfiguration` class (flutter/engine#19652)

* 22fb58b update nullability of drawAtlas methods and flesh out docs (flutter/engine#20176)

* bcc43df Roll Dart SDK from ea6bde577d1c to 033a81d924b9 (23 revisions) (flutter/engine#20186)

* cb4bb93 [web] increase number of shards. sync engine web tests same as flutter repo (flutter/engine#20164)

* d986b8d Enable linting in several files (flutter/engine#20134)

* 7dd092d Enable more linting (flutter/engine#20187)

* 3cc86ac Roll Dart SDK from 033a81d924b9 to ad5bcf16f1c8 (9 revisions) (flutter/engine#20191)

* 5ca8a2a Roll Dart SDK from ad5bcf16f1c8 to d169af6f7d8f (1 revision) (flutter/engine#20192)

* 4de0c04 Roll Dart SDK from d169af6f7d8f to 7e6c55e3aaf5 (1 revision) (flutter/engine#20196)

* 908fe01 Fix navigation message relay. (flutter/engine#20193)

* f1b3b69 Roll Dart SDK from 7e6c55e3aaf5 to 365525432a70 (2 revisions) (flutter/engine#20197)

* 8fbdd3f Fix parameter names

* 083282e Fix Implments typo
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