Skip to content

Conversation

jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Apr 21, 2020

Description

Move FlutterView and related RPCs to the package:vm_service implementation. Update some getIsolate calls with catchError to match previous behavior.

  • Updates tests that were previously mocking FlutterViews to use real views
  • Moves the FlutterView cache from VM to FlutterDevice
  • Catch SentinelException during Isolate.kill

#52179

Maybe #55552

@fluttergithubbot fluttergithubbot added tool Affects the "flutter" command-line tool. See also t: labels. work in progress; do not review labels Apr 21, 2020
for (final FlutterView flutterView in views) {
final vm_service.Isolate isolate = await vmService
.getIsolate(flutterView.uiIsolate.id)
.catchError((dynamic error, StackTrace stackTrace) {
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 added a catchError field to all of these because it seems like that is what we were doing before:

https://github.com/flutter/flutter/blob/master/packages/flutter_tools/lib/src/vmservice.dart#L1035

Though before we might have been re-using invalid isolates, which is probably worse

Copy link
Member

Choose a reason for hiding this comment

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

Would a trace message here be useful?

Copy link
Member

Choose a reason for hiding this comment

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

Also, this pattern is repeated several times, so creating a new method somewhere for this could be a good cleanup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous trace was not useful, since we don't seem to hit this case often.

Updated to an extension method on VmService

}
final List<FlutterView> _views = <FlutterView>[];

List<FlutterView> get views {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved the filtering here instead of on VM

String reason,
bool benchmarkMode = false,
}) async {
if (!_isPaused()) {
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 could not find a good justification for keeping the pause check

Copy link
Member

Choose a reason for hiding this comment

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

#9733 fixed flutter/flutter-intellij#969, make sure removing this check doesn't regress that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, should have been more clear here:

We have a hot reload test in integration.shard that performs a hot restart while paused and that still passes with this removed. I've also verified locally that this listViews RPC returns successfully while paused:

An Observatory debugger and profiler on Pixel 4 is available at: http://127.0.0.1:50743/Nb1i5jI30FQ=/


Performing hot reload...
The application is paused due in the debugger; interface might not update.
Reloaded 0 of 660 libraries in 107ms.

Performing hot reload...
The application is paused due in the debugger; interface might not update.
Reloaded 0 of 660 libraries in 100ms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was most likely a bug in the implementation of listVews. I can do some more research to try and figure out when it was fixed, but for now we should have good coverage

case ServiceEvent.kPauseException: message.write('paused in the debugger after an exception was thrown'); break;
case ServiceEvent.kPausePostRequest: message.write('paused'); break;
case '': message.write('paused for various reasons'); break;
case vm_service.EventKind.kPauseStart:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved statements to different lines, updated constants to point to vm_service

@jonahwilliams jonahwilliams marked this pull request as ready for review April 24, 2020 14:26
for (final FlutterView flutterView in views) {
final vm_service.Isolate isolate = await vmService
.getIsolate(flutterView.uiIsolate.id)
.catchError((dynamic error, StackTrace stackTrace) {
Copy link
Member

Choose a reason for hiding this comment

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

Would a trace message here be useful?

for (final FlutterView flutterView in views) {
final vm_service.Isolate isolate = await vmService
.getIsolate(flutterView.uiIsolate.id)
.catchError((dynamic error, StackTrace stackTrace) {
Copy link
Member

Choose a reason for hiding this comment

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

Also, this pattern is repeated several times, so creating a new method somewhere for this could be a good cleanup.

assert(!view.uiIsolate.pauseEvent.isPauseEvent);
futures.add(vmService.flutterExit(
isolateId: view.uiIsolate.id,
));
Copy link
Member

Choose a reason for hiding this comment

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

Regarding the comment below on 282, what would go wrong if we don't wait for flutterExit to fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its not if it fails its that when it succeeds the engine goes down so there is no signal. I could re-arrange this to instead listen to the vm_service done signal, that would remove the need for the timeout

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the logic to be a bit simpler, and catch any SentinelException (would be thrown if we exited after the app crashed, for example)

}));
final vm_service.VM vm = await device.vmService.getVM();
for (final vm_service.IsolateRef isolateRef in vm.isolates) {
if (!uiIsolatesIds.contains(isolateRef.id)) {
Copy link
Member

Choose a reason for hiding this comment

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

Consider flipping the sense of the if with a continue under it, and unindenting the rest of the loop body.

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

// Reload the isolate data.
await Future.wait(<Future<void>>[
for (final FlutterDevice device in flutterDevices)
device.refreshViews()
Copy link
Member

Choose a reason for hiding this comment

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

Is device.refreshViews() now also doing the uiIsolate.reload()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we only need the isolateRef data so reloading the full isolate isn't necessary (and we do this as needed anyway below)

kind == vm_service.EventKind.kPauseException ||
kind == vm_service.EventKind.kPausePostRequest ||
kind == vm_service.EventKind.kNone;
}
Copy link
Member

Choose a reason for hiding this comment

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

MIssing newline at EOF

final Completer<void> sawDebuggerPausedMessage = Completer<void>();
final StreamSubscription<String> subscription = _flutter.stdout.listen(
(String line) {
print('LOG: $line');
Copy link
Member

Choose a reason for hiding this comment

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

stray print?

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

return;
}
await flutterDeprecatedVmService.vm.refreshViews(waitForViews: true);
final List<FlutterView> newViews = await vmService.getFlutterViews();
Copy link
Member

Choose a reason for hiding this comment

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

How are they new? Isn't this all of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to reflect this is an update of the view list

String reason,
bool benchmarkMode = false,
}) async {
if (!_isPaused()) {
Copy link
Member

Choose a reason for hiding this comment

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

#9733 fixed flutter/flutter-intellij#969, make sure removing this check doesn't regress that.


final Stopwatch reloadTimer = Stopwatch()..start();

if (!_isPaused()) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here re: #9733

Copy link
Member

@zanderso zanderso left a comment

Choose a reason for hiding this comment

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

lgtm

/// been collected.
Future<vm_service.Isolate> getIsolateOrNull(String isolateId) {
return getIsolate(isolateId)
.catchError((dynamic error, StackTrace stackTrace) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: 2 space indent on a continued line.

@jonahwilliams jonahwilliams merged commit 2e50fd7 into flutter:master Apr 27, 2020
@jonahwilliams jonahwilliams deleted the remove_more_vm_service branch April 27, 2020 21:16
jonahwilliams pushed a commit that referenced this pull request Apr 27, 2020
jonahwilliams pushed a commit that referenced this pull request Apr 27, 2020
@jonahwilliams jonahwilliams restored the remove_more_vm_service branch April 27, 2020 21:28
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants