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
25e6cc67
Commit
25e6cc67
authored
Dec 12, 2016
by
Yegor
Committed by
GitHub
Dec 12, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: add timeout to VM service client (#7175)
parent
05866a27
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
18 deletions
+31
-18
vmservice.dart
packages/flutter_tools/lib/src/vmservice.dart
+31
-18
No files found.
packages/flutter_tools/lib/src/vmservice.dart
View file @
25e6cc67
...
...
@@ -14,9 +14,15 @@ import 'package:web_socket_channel/io.dart';
import
'globals.dart'
;
/// The default VM service request timeout.
const
Duration
kDefaultRequestTimeout
=
const
Duration
(
seconds:
10
);
/// Used for RPC requests that may take a long time.
const
Duration
kLongRequestTimeout
=
const
Duration
(
minutes:
1
);
/// A connection to the Dart VM Service.
class
VMService
{
VMService
.
_
(
this
.
peer
,
this
.
httpAddress
,
this
.
wsAddress
)
{
VMService
.
_
(
this
.
peer
,
this
.
httpAddress
,
this
.
wsAddress
,
this
.
_requestTimeout
)
{
_vm
=
new
VM
.
_empty
(
this
);
peer
.
registerMethod
(
'streamNotify'
,
(
rpc
.
Parameters
event
)
{
...
...
@@ -24,8 +30,11 @@ class VMService {
});
}
/// Connect to '127.0.0.1' at [port].
static
Future
<
VMService
>
connect
(
Uri
httpUri
)
async
{
/// Connect to a Dart VM Service at [httpUri].
///
/// Requests made via the returns [VMService] time out after [requestTimeout]
/// amount of time, which is [kDefaultRequestTimeout] by default.
static
Future
<
VMService
>
connect
(
Uri
httpUri
,
{
Duration
requestTimeout:
kDefaultRequestTimeout
})
async
{
Uri
wsUri
=
httpUri
.
replace
(
scheme:
'ws'
,
path:
path
.
join
(
httpUri
.
path
,
'ws'
));
WebSocket
ws
;
try
{
...
...
@@ -35,11 +44,13 @@ class VMService {
}
rpc
.
Peer
peer
=
new
rpc
.
Peer
.
withoutJson
(
jsonDocument
.
bind
(
new
IOWebSocketChannel
(
ws
).
cast
()));
peer
.
listen
();
return
new
VMService
.
_
(
peer
,
httpUri
,
wsUri
);
return
new
VMService
.
_
(
peer
,
httpUri
,
wsUri
,
requestTimeout
);
}
final
Uri
httpAddress
;
final
Uri
wsAddress
;
final
rpc
.
Peer
peer
;
final
Duration
_requestTimeout
;
VM
_vm
;
/// The singleton [VM] object. Owns [Isolate] and [FlutterView] objects.
...
...
@@ -558,13 +569,20 @@ class VM extends ServiceObjectOwner {
/// Invoke the RPC and return the raw response.
Future
<
Map
<
String
,
dynamic
>>
invokeRpcRaw
(
String
method
,
[
Map
<
String
,
dynamic
>
params
])
async
{
String
method
,
[
Map
<
String
,
dynamic
>
params
,
Duration
timeout
])
async
{
if
(
params
==
null
)
{
params
=
<
String
,
dynamic
>{};
}
Map
<
String
,
dynamic
>
result
=
await
_vmService
.
peer
.
sendRequest
(
method
,
params
);
return
result
;
try
{
Map
<
String
,
dynamic
>
result
=
await
_vmService
.
peer
.
sendRequest
(
method
,
params
)
.
timeout
(
timeout
??
_vmService
.
_requestTimeout
);
return
result
;
}
on
TimeoutException
catch
(
_
)
{
printError
(
'Request to Dart VM Service timed out:
$method
(
$params
)'
);
rethrow
;
}
}
/// Invoke the RPC and return a ServiceObject response.
...
...
@@ -661,7 +679,7 @@ class VM extends ServiceObjectOwner {
}
Future
<
Map
<
String
,
dynamic
>>
getVMTimeline
()
{
return
invokeRpcRaw
(
'_getVMTimeline'
,
<
String
,
dynamic
>
{});
return
invokeRpcRaw
(
'_getVMTimeline'
,
<
String
,
dynamic
>
{}
,
kLongRequestTimeout
);
}
Future
<
Null
>
refreshViews
()
async
{
...
...
@@ -724,7 +742,7 @@ class Isolate extends ServiceObjectOwner {
/// Invoke the RPC and return the raw response.
Future
<
Map
<
String
,
dynamic
>>
invokeRpcRaw
(
String
method
,
[
Map
<
String
,
dynamic
>
params
])
{
String
method
,
[
Map
<
String
,
dynamic
>
params
,
Duration
timeout
])
{
// Inject the 'isolateId' parameter.
if
(
params
==
null
)
{
params
=
<
String
,
dynamic
>{
...
...
@@ -733,7 +751,7 @@ class Isolate extends ServiceObjectOwner {
}
else
{
params
[
'isolateId'
]
=
id
;
}
return
vm
.
invokeRpcRaw
(
method
,
params
);
return
vm
.
invokeRpcRaw
(
method
,
params
,
timeout
);
}
/// Invoke the RPC and return a ServiceObject response.
...
...
@@ -793,9 +811,9 @@ class Isolate extends ServiceObjectOwner {
String
method
,
[
Map
<
String
,
dynamic
>
params
])
async
{
try
{
return
await
invokeRpcRaw
(
method
,
params
);
}
catch
(
e
)
{
}
on
rpc
.
RpcException
catch
(
e
)
{
// If an application is not using the framework
if
(
_isMethodNotFoundException
(
e
)
)
if
(
e
.
code
==
rpc_error_code
.
METHOD_NOT_FOUND
)
return
null
;
rethrow
;
}
...
...
@@ -818,11 +836,6 @@ class Isolate extends ServiceObjectOwner {
return
state
;
}
static
bool
_isMethodNotFoundException
(
dynamic
e
)
{
return
(
e
is
rpc
.
RpcException
)
&&
(
e
.
code
==
rpc_error_code
.
METHOD_NOT_FOUND
);
}
// Reload related extension methods.
Future
<
Map
<
String
,
dynamic
>>
flutterReassemble
()
async
{
return
await
invokeFlutterExtensionRpcRaw
(
'ext.flutter.reassemble'
);
...
...
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