[flutter_tools] fix crash when IsolateRef returns sentinel (#50611)
This commit is contained in:
@@ -132,8 +132,12 @@ class FallbackDiscovery {
|
||||
final VmService vmService = await _vmServiceConnectUri(assumedWsUri.toString());
|
||||
final VM vm = await vmService.getVM();
|
||||
for (final IsolateRef isolateRefs in vm.isolates) {
|
||||
final Isolate isolate = await vmService.getIsolate(isolateRefs.id) as Isolate;
|
||||
final LibraryRef library = isolate.rootLib;
|
||||
final dynamic isolateResponse = await vmService.getIsolate(isolateRefs.id);
|
||||
if (isolateResponse is Sentinel) {
|
||||
// Might have been a Sentinel. Try again later.
|
||||
throw Exception('Expected Isolate but found Sentinel: $isolateResponse');
|
||||
}
|
||||
final LibraryRef library = (isolateResponse as Isolate).rootLib;
|
||||
if (library.uri.startsWith('package:$packageName')) {
|
||||
UsageEvent(_kEventName, 'success').send();
|
||||
return Uri.parse('http://localhost:$hostPort');
|
||||
|
||||
@@ -67,6 +67,35 @@ void main() {
|
||||
), Uri.parse('http://localhost:1'));
|
||||
});
|
||||
|
||||
testUsingContext('Selects mdns discovery if VM service connecton fails due to Sentinel', () async {
|
||||
when(mockVmService.getVM()).thenAnswer((Invocation invocation) async {
|
||||
return VM()..isolates = <IsolateRef>[
|
||||
IsolateRef(),
|
||||
];
|
||||
});
|
||||
when(mockVmService.getIsolate(any)).thenAnswer((Invocation invocation) async {
|
||||
return Sentinel();
|
||||
});
|
||||
|
||||
when(mockMDnsObservatoryDiscovery.getObservatoryUri(
|
||||
'hello',
|
||||
null, // Device
|
||||
usesIpv6: false,
|
||||
hostVmservicePort: 1,
|
||||
)).thenAnswer((Invocation invocation) async {
|
||||
return Uri.parse('http://localhost:1234');
|
||||
});
|
||||
|
||||
expect(await fallbackDiscovery.discover(
|
||||
assumedDevicePort: 23,
|
||||
deivce: null,
|
||||
hostVmservicePort: 1,
|
||||
packageId: 'hello',
|
||||
usesIpv6: false,
|
||||
packageName: 'hello',
|
||||
), Uri.parse('http://localhost:1234'));
|
||||
});
|
||||
|
||||
testUsingContext('Selects mdns discovery if VM service connecton fails', () async {
|
||||
when(mockVmService.getVM()).thenThrow(Exception());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user