Skip to content

Conversation

@Hixie
Copy link
Contributor

@Hixie Hixie commented Oct 25, 2018

Fixes #19273

@Hixie
Copy link
Contributor Author

Hixie commented Oct 25, 2018

cc @zanderso

@Hixie Hixie changed the title Fix a race condition in vmservice_test.dart [O] Fix a race condition in vmservice_test.dart Oct 25, 2018
@tvolkert
Copy link
Contributor

/cc @aam

Copy link
Contributor

Choose a reason for hiding this comment

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

Curious: is there a reason why i++ is less desirable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in this case, not really. In the general case, ++ suffix can be less efficient (since it has to store the value, then increment it, then use it), so ++ prefix is preferred. But that's ugly. So I pre-emptively turn ++ into the equivalent += 1 to make people more comfortable with += 1 so that the issue of ++ prefix can go away. :-)

Copy link
Contributor

Choose a reason for hiding this comment

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

@visibleForTesting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it matter in this case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should/can this be List<Object> too, since you change dynamic to Object below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the JSON logic creates List<dynamic>s, not List<Object>s.

Copy link
Contributor

Choose a reason for hiding this comment

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

=> invokeRpcRaw('getVM');

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

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 my intent was not to await here, so refreshViews could continue without blocking. Was there a reason you put await back?

Copy link
Contributor

Choose a reason for hiding this comment

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

The caller of refreshViews() can choose to not await the returned future. The use of async/await here is semantically equivalent to what you were trying to do with the Completer.

Copy link
Member

Choose a reason for hiding this comment

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

Ok, got it.

Copy link
Contributor Author

@Hixie Hixie Oct 26, 2018

Choose a reason for hiding this comment

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

yeah these are identical semantically. I happened to have already made this change on my branch; I didn't put the await back so much as have to resolve the merge, and I went with the shorter option. :-)

Copy link
Member

Choose a reason for hiding this comment

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

Similarly, can we avoid awaiting in this method and instead let caller await if it decided it needed to?

Copy link
Contributor

Choose a reason for hiding this comment

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

The return value of this method will be a future that will complete when all the futures have completed. It's still up to the caller to await the future returned by this method or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

await future; ...rest of method... is exactly equivalent to return future.then(...rest of method...).

Copy link
Contributor

@tvolkert tvolkert Oct 26, 2018

Choose a reason for hiding this comment

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

Add a comment explaining that upon completion of this RPC, _viewCache will be updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

Choose a reason for hiding this comment

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

Can listViews ever legitimately turn up no FlutterView instances? If so, we'll retry here until we eventually fail, even though there was no failure...

Copy link
Contributor

Choose a reason for hiding this comment

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

Though I guess that's what waitForViews is for (why why it defaults to false)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know the answer to your first question, but if so, I don't know how we would distinguish that case from the normal case where we don't want to return until we have a view.

The argument defaults to false so as to not change the default behaviour in the regular case; only in the specific case where I believe we definitely need a view did I set it to true.

Copy link
Contributor

Choose a reason for hiding this comment

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

No need for async

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@tvolkert tvolkert left a comment

Choose a reason for hiding this comment

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

LGTM

@Hixie
Copy link
Contributor Author

Hixie commented Oct 26, 2018

thanks for the reviews, will land on green

@Hixie Hixie merged commit 5e7b0a3 into flutter:master Oct 27, 2018
@Hixie Hixie deleted the vmservice branch October 27, 2018 23:50
@Hixie
Copy link
Contributor Author

Hixie commented Oct 28, 2018

Reverting this since it broke a test. cc @aam we might want to work together on this... both of our patches in the same area had the same problem.

Hixie added a commit that referenced this pull request Oct 28, 2018
Hixie added a commit that referenced this pull request Oct 28, 2018
* Revert "[H] Created a variant of InheritedWidget specifically for Listenables (#23393)"

This reverts commit 9313285.

* Revert "Fix a race condition in vmservice_test.dart (#23529)"

This reverts commit 5e7b0a3.
@Hixie
Copy link
Contributor Author

Hixie commented Oct 28, 2018

Specifically, named_isolates_test failed.

for (FlutterDevice device in flutterDevices)
await device.refreshViews();
futures.add(device.refreshViews());
await Future.wait(futures);
Copy link
Member

Choose a reason for hiding this comment

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

This is the change that breaks named_isolates_test.
From what I can tell flutter engine is getting stuck processing two concurrent listViews requests https://github.com/flutter/engine/blob/master/runtime/service_protocol.cc#L237.

cc @jason-simmons @chinmaygarde

Copy link
Member

Choose a reason for hiding this comment

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

To reproduce the failure pick up this new implementation of refreshViews() method and run named_isolates_test locally from $FH/flutter/dev/devicelab: $FH/flutter/bin/cache/dart-sdk/bin/dart bin/run.dart -t named_isolates_test

Copy link
Member

Choose a reason for hiding this comment

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

I am fixing refreshViews so it is app-wide, rather than isolate-specific message, that should fix deadlock in the engine((in 89665ac). @chinmaygarde is making engine more robust to these kind of scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

awesome.

Xavjer pushed a commit to Xavjer/flutter that referenced this pull request Nov 1, 2018
Xavjer pushed a commit to Xavjer/flutter that referenced this pull request Nov 1, 2018
* Revert "[H] Created a variant of InheritedWidget specifically for Listenables (flutter#23393)"

This reverts commit 9313285.

* Revert "Fix a race condition in vmservice_test.dart (flutter#23529)"

This reverts commit 5e7b0a3.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flutter_tester hangs on linux workstation

4 participants