Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7f564b74
Unverified
Commit
7f564b74
authored
Mar 10, 2020
by
Zachary Anderson
Committed by
GitHub
Mar 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[flutter_tools] Handle StateError in ProtocolDiscovery.uri (#52337)
parent
5d289721
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
94 additions
and
23 deletions
+94
-23
android_device.dart
packages/flutter_tools/lib/src/android/android_device.dart
+7
-2
desktop_device.dart
packages/flutter_tools/lib/src/desktop_device.dart
+9
-3
fallback_discovery.dart
packages/flutter_tools/lib/src/ios/fallback_discovery.dart
+40
-10
simulators.dart
packages/flutter_tools/lib/src/ios/simulators.dart
+9
-3
protocol_discovery.dart
packages/flutter_tools/lib/src/protocol_discovery.dart
+9
-2
flutter_tester.dart
packages/flutter_tools/lib/src/tester/flutter_tester.dart
+12
-3
protocol_discovery_test.dart
...ter_tools/test/general.shard/protocol_discovery_test.dart
+8
-0
No files found.
packages/flutter_tools/lib/src/android/android_device.dart
View file @
7f564b74
...
...
@@ -629,11 +629,16 @@ class AndroidDevice extends Device {
// TODO(danrubel): Waiting for observatory services can be made common across all devices.
try
{
Uri
observatoryUri
;
if
(
debuggingOptions
.
buildInfo
.
isDebug
||
debuggingOptions
.
buildInfo
.
isProfile
)
{
observatoryUri
=
await
observatoryDiscovery
.
uri
;
if
(
observatoryUri
==
null
)
{
globals
.
printError
(
'Error waiting for a debug connection: '
'The log reader stopped unexpectedly'
,
);
return
LaunchResult
.
failed
();
}
}
return
LaunchResult
.
succeeded
(
observatoryUri:
observatoryUri
);
}
on
Exception
catch
(
error
)
{
globals
.
printError
(
'Error waiting for a debug connection:
$error
'
);
...
...
packages/flutter_tools/lib/src/desktop_device.dart
View file @
7f564b74
...
...
@@ -114,14 +114,20 @@ abstract class DesktopDevice extends Device {
);
try
{
final
Uri
observatoryUri
=
await
observatoryDiscovery
.
uri
;
onAttached
(
package
,
buildMode
,
process
);
return
LaunchResult
.
succeeded
(
observatoryUri:
observatoryUri
);
if
(
observatoryUri
!=
null
)
{
onAttached
(
package
,
buildMode
,
process
);
return
LaunchResult
.
succeeded
(
observatoryUri:
observatoryUri
);
}
globals
.
printError
(
'Error waiting for a debug connection: '
'The log reader stopped unexpectedly.'
,
);
}
on
Exception
catch
(
error
)
{
globals
.
printError
(
'Error waiting for a debug connection:
$error
'
);
return
LaunchResult
.
failed
();
}
finally
{
await
observatoryDiscovery
.
cancel
();
}
return
LaunchResult
.
failed
();
}
@override
...
...
packages/flutter_tools/lib/src/ios/fallback_discovery.dart
View file @
7f564b74
...
...
@@ -42,7 +42,8 @@ class FallbackDiscovery {
@required
MDnsObservatoryDiscovery
mDnsObservatoryDiscovery
,
@required
Logger
logger
,
@required
ProtocolDiscovery
protocolDiscovery
,
Future
<
VmService
>
Function
(
String
wsUri
,
{
Log
log
})
vmServiceConnectUri
=
vm_service_io
.
vmServiceConnectUri
,
Future
<
VmService
>
Function
(
String
wsUri
,
{
Log
log
})
vmServiceConnectUri
=
vm_service_io
.
vmServiceConnectUri
,
})
:
_logger
=
logger
,
_mDnsObservatoryDiscovery
=
mDnsObservatoryDiscovery
,
_portForwarder
=
portForwarder
,
...
...
@@ -83,19 +84,33 @@ class FallbackDiscovery {
hostVmservicePort:
hostVmservicePort
,
);
if
(
result
!=
null
)
{
UsageEvent
(
_kEventName
,
'mdns-success'
,
flutterUsage:
globals
.
flutterUsage
).
send
();
UsageEvent
(
_kEventName
,
'mdns-success'
,
flutterUsage:
globals
.
flutterUsage
,
).
send
();
return
result
;
}
}
on
Exception
catch
(
err
)
{
_logger
.
printTrace
(
err
.
toString
());
}
_logger
.
printTrace
(
'Failed to connect with mDNS, falling back to log scanning'
);
UsageEvent
(
_kEventName
,
'mdns-failure'
,
flutterUsage:
globals
.
flutterUsage
).
send
();
UsageEvent
(
_kEventName
,
'mdns-failure'
,
flutterUsage:
globals
.
flutterUsage
,
).
send
();
try
{
final
Uri
result
=
await
_protocolDiscovery
.
uri
;
UsageEvent
(
_kEventName
,
'fallback-success'
,
flutterUsage:
globals
.
flutterUsage
).
send
();
return
result
;
if
(
result
!=
null
)
{
UsageEvent
(
_kEventName
,
'fallback-success'
,
flutterUsage:
globals
.
flutterUsage
,
).
send
();
return
result
;
}
}
on
ArgumentError
{
// In the event of an invalid InternetAddress, this code attempts to catch
// an ArgumentError from protocol_discovery.dart
...
...
@@ -103,7 +118,11 @@ class FallbackDiscovery {
_logger
.
printTrace
(
err
.
toString
());
}
_logger
.
printTrace
(
'Failed to connect with log scanning'
);
UsageEvent
(
_kEventName
,
'fallback-failure'
,
flutterUsage:
globals
.
flutterUsage
).
send
();
UsageEvent
(
_kEventName
,
'fallback-failure'
,
flutterUsage:
globals
.
flutterUsage
,
).
send
();
return
null
;
}
...
...
@@ -117,7 +136,10 @@ class FallbackDiscovery {
int
hostPort
;
Uri
assumedWsUri
;
try
{
hostPort
=
await
_portForwarder
.
forward
(
assumedDevicePort
,
hostPort:
hostVmservicePort
);
hostPort
=
await
_portForwarder
.
forward
(
assumedDevicePort
,
hostPort:
hostVmservicePort
,
);
assumedWsUri
=
Uri
.
parse
(
'ws://localhost:
$hostPort
/ws'
);
}
on
Exception
catch
(
err
)
{
_logger
.
printTrace
(
err
.
toString
());
...
...
@@ -132,17 +154,25 @@ class FallbackDiscovery {
Exception
firstException
;
while
(
attempts
<
5
)
{
try
{
final
VmService
vmService
=
await
_vmServiceConnectUri
(
assumedWsUri
.
toString
());
final
VmService
vmService
=
await
_vmServiceConnectUri
(
assumedWsUri
.
toString
(),
);
final
VM
vm
=
await
vmService
.
getVM
();
for
(
final
IsolateRef
isolateRefs
in
vm
.
isolates
)
{
final
dynamic
isolateResponse
=
await
vmService
.
getIsolate
(
isolateRefs
.
id
);
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'
,
flutterUsage:
globals
.
flutterUsage
).
send
();
UsageEvent
(
_kEventName
,
'success'
,
flutterUsage:
globals
.
flutterUsage
,
).
send
();
return
Uri
.
parse
(
'http://localhost:
$hostPort
'
);
}
}
...
...
packages/flutter_tools/lib/src/ios/simulators.dart
View file @
7f564b74
...
...
@@ -445,13 +445,19 @@ class IOSSimulator extends Device {
try
{
final
Uri
deviceUri
=
await
observatoryDiscovery
.
uri
;
return
LaunchResult
.
succeeded
(
observatoryUri:
deviceUri
);
if
(
deviceUri
!=
null
)
{
return
LaunchResult
.
succeeded
(
observatoryUri:
deviceUri
);
}
globals
.
printError
(
'Error waiting for a debug connection: '
'The log reader failed unexpectedly'
,
);
}
on
Exception
catch
(
error
)
{
globals
.
printError
(
'Error waiting for a debug connection:
$error
'
);
return
LaunchResult
.
failed
();
}
finally
{
await
observatoryDiscovery
.
cancel
();
await
observatoryDiscovery
?
.
cancel
();
}
return
LaunchResult
.
failed
();
}
Future
<
void
>
_setupUpdatedApplicationBundle
(
covariant
BuildableIOSApp
app
,
BuildInfo
buildInfo
,
String
mainPath
)
async
{
...
...
packages/flutter_tools/lib/src/protocol_discovery.dart
View file @
7f564b74
...
...
@@ -64,10 +64,17 @@ class ProtocolDiscovery {
_BufferedStreamController
<
Uri
>
_uriStreamController
;
/// The discovered service URL.
///
/// Returns null if the log reader shuts down before any uri is found.
///
/// Use [uris] instead.
// TODO(egarciad): replace `uri` for `uris`.
Future
<
Uri
>
get
uri
{
return
uris
.
first
;
Future
<
Uri
>
get
uri
async
{
try
{
return
await
uris
.
first
;
}
on
StateError
{
return
null
;
}
}
/// The discovered service URLs.
...
...
packages/flutter_tools/lib/src/tester/flutter_tester.dart
View file @
7f564b74
...
...
@@ -157,6 +157,7 @@ class FlutterTesterDevice extends Device {
command
.
add
(
applicationKernelFilePath
);
ProtocolDiscovery
observatoryDiscovery
;
try
{
globals
.
printTrace
(
command
.
join
(
' '
));
...
...
@@ -185,7 +186,7 @@ class FlutterTesterDevice extends Device {
return
LaunchResult
.
succeeded
();
}
final
ProtocolDiscovery
observatoryDiscovery
=
ProtocolDiscovery
.
observatory
(
observatoryDiscovery
=
ProtocolDiscovery
.
observatory
(
getLogReader
(),
hostPort:
debuggingOptions
.
hostVmServicePort
,
devicePort:
debuggingOptions
.
deviceVmServicePort
,
...
...
@@ -193,11 +194,19 @@ class FlutterTesterDevice extends Device {
);
final
Uri
observatoryUri
=
await
observatoryDiscovery
.
uri
;
return
LaunchResult
.
succeeded
(
observatoryUri:
observatoryUri
);
if
(
observatoryUri
!=
null
)
{
return
LaunchResult
.
succeeded
(
observatoryUri:
observatoryUri
);
}
globals
.
printError
(
'Failed to launch
$package
: '
'The log reader failed unexpectedly.'
,
);
}
on
Exception
catch
(
error
)
{
globals
.
printError
(
'Failed to launch
$package
:
$error
'
);
return
LaunchResult
.
failed
();
}
finally
{
await
observatoryDiscovery
?.
cancel
();
}
return
LaunchResult
.
failed
();
}
@override
...
...
packages/flutter_tools/test/general.shard/protocol_discovery_test.dart
View file @
7f564b74
...
...
@@ -112,6 +112,14 @@ void main() {
expect
(
discoverer
.
uri
,
throwsA
(
isFormatException
));
});
testUsingContext
(
'uri is null when the log reader closes early'
,
()
async
{
initialize
();
final
Future
<
Uri
>
uriFuture
=
discoverer
.
uri
;
await
logReader
.
dispose
();
expect
(
await
uriFuture
,
isNull
);
});
testUsingContext
(
'uri waits for correct log line'
,
()
async
{
initialize
();
final
Future
<
Uri
>
uriFuture
=
discoverer
.
uri
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment