Unverified Commit cf6c33e5 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] fix port leak in flutter_driver (#70999)

parent 226532b1
...@@ -530,7 +530,6 @@ class VMServiceFlutterDriver extends FlutterDriver { ...@@ -530,7 +530,6 @@ class VMServiceFlutterDriver extends FlutterDriver {
} }
} }
/// The connection function used by [FlutterDriver.connect]. /// The connection function used by [FlutterDriver.connect].
/// ///
/// Overwrite this function if you require a custom method for connecting to /// Overwrite this function if you require a custom method for connecting to
...@@ -563,13 +562,18 @@ Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic> headers) ...@@ -563,13 +562,18 @@ Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic> headers)
while (true) { while (true) {
try { try {
socket = await WebSocket.connect(webSocketUrl, headers: headers); socket = await WebSocket.connect(webSocketUrl, headers: headers);
final StreamController<dynamic> controller = StreamController<dynamic>();
final Completer<void> streamClosedCompleter = Completer<void>();
socket.listen(
(dynamic data) => controller.add(data),
onDone: () => streamClosedCompleter.complete(),
);
final vms.VmService service = vms.VmService( final vms.VmService service = vms.VmService(
socket, controller.stream,
socket.add, socket.add,
log: null, log: null,
disposeHandler: () async { disposeHandler: () => socket.close(),
await socket.close(); streamClosed: streamClosedCompleter.future
},
); );
// This call is to ensure we are able to establish a connection instead of // This call is to ensure we are able to establish a connection instead of
// keeping on trucking and failing farther down the process. // keeping on trucking and failing farther down the process.
...@@ -586,7 +590,6 @@ Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic> headers) ...@@ -586,7 +590,6 @@ Future<vms.VmService> _waitAndConnect(String url, Map<String, dynamic> headers)
} }
} }
/// The amount of time we wait prior to making the next attempt to connect to /// The amount of time we wait prior to making the next attempt to connect to
/// the VM service. /// the VM service.
const Duration _kPauseBetweenReconnectAttempts = Duration(seconds: 1); const Duration _kPauseBetweenReconnectAttempts = Duration(seconds: 1);
......
...@@ -235,15 +235,8 @@ class FlutterDriverService extends DriverService { ...@@ -235,15 +235,8 @@ class FlutterDriverService extends DriverService {
int driverPort, int driverPort,
List<String> browserDimension, List<String> browserDimension,
}) async { }) async {
// Check if package:test is available. If not, fall back to invoking
// the test script directly. `pub run test` is strictly better because
// in the even that a socket or something similar is left open, the
// test runner will correctly shutdown the VM instead of hanging forever.
return _processUtils.stream(<String>[ return _processUtils.stream(<String>[
_dartSdkPath, _dartSdkPath,
if (packageConfig['test'] != null)
...<String>['pub', 'run', 'test', ...arguments, testFile, '-rexpanded']
else
...<String>[...arguments, testFile, '-rexpanded'], ...<String>[...arguments, testFile, '-rexpanded'],
], environment: <String, String>{ ], environment: <String, String>{
'VM_SERVICE_URL': _vmServiceUri, 'VM_SERVICE_URL': _vmServiceUri,
......
...@@ -153,7 +153,7 @@ void main() { ...@@ -153,7 +153,7 @@ void main() {
]); ]);
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[ final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand( const FakeCommand(
command: <String>['dart', 'pub', 'run', 'test', '--enable-experiment=non-nullable', 'foo.test', '-rexpanded'], command: <String>['dart', '--enable-experiment=non-nullable', 'foo.test', '-rexpanded'],
exitCode: 23, exitCode: 23,
environment: <String, String>{ environment: <String, String>{
'FOO': 'BAR', 'FOO': 'BAR',
...@@ -214,7 +214,7 @@ void main() { ...@@ -214,7 +214,7 @@ void main() {
]); ]);
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[ final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand( const FakeCommand(
command: <String>['dart', 'pub', 'run', 'test', 'foo.test', '-rexpanded'], command: <String>['dart', 'foo.test', '-rexpanded'],
exitCode: 11, exitCode: 11,
environment: <String, String>{ environment: <String, String>{
'VM_SERVICE_URL': 'http://127.0.0.1:1234/' 'VM_SERVICE_URL': 'http://127.0.0.1:1234/'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment