Roll package:dds to 1.4.0 and update error handling (#66836)
This commit is contained in:
@@ -2,9 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dds/dds.dart' as dds;
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import 'common.dart';
|
||||
import 'io.dart' as io;
|
||||
import 'logger.dart';
|
||||
|
||||
@@ -18,6 +21,9 @@ class DartDevelopmentService {
|
||||
|
||||
Uri get uri => _ddsInstance.uri;
|
||||
|
||||
Future<void> get done => _completer.future;
|
||||
final Completer<void> _completer = Completer<void>();
|
||||
|
||||
Future<void> startDartDevelopmentService(
|
||||
Uri observatoryUri,
|
||||
int hostPort,
|
||||
@@ -43,9 +49,11 @@ class DartDevelopmentService {
|
||||
enableAuthCodes: !disableServiceAuthCodes,
|
||||
ipv6: ipv6,
|
||||
);
|
||||
unawaited(_ddsInstance.done.whenComplete(_completer.complete));
|
||||
logger.printTrace('DDS is listening at ${_ddsInstance.uri}.');
|
||||
} on dds.DartDevelopmentServiceException catch (e) {
|
||||
logger.printError('Warning: Failed to start DDS: ${e.message}');
|
||||
logger.printTrace('Warning: Failed to start DDS: ${e.message}');
|
||||
_completer.complete();
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,24 +230,44 @@ class FlutterDevice {
|
||||
isWaitingForVm = true;
|
||||
vm_service.VmService service;
|
||||
if (!disableDds) {
|
||||
await device.dds.startDartDevelopmentService(
|
||||
observatoryUri,
|
||||
ddsPort,
|
||||
ipv6,
|
||||
disableServiceAuthCodes,
|
||||
);
|
||||
// This first try block is meant to catch errors that occur during DDS startup
|
||||
// (e.g., failure to bind to a port, failure to connect to the VM service,
|
||||
// attaching to a VM service with existing clients, etc.).
|
||||
try {
|
||||
await device.dds.startDartDevelopmentService(
|
||||
observatoryUri,
|
||||
ddsPort,
|
||||
ipv6,
|
||||
disableServiceAuthCodes,
|
||||
);
|
||||
} on Exception catch (e) {
|
||||
globals.printTrace('Fail to connect to service protocol: $observatoryUri: $e');
|
||||
if (!completer.isCompleted && !_isListeningForObservatoryUri) {
|
||||
completer.completeError('failed to connect to $observatoryUri');
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
// This second try block handles cases where the VM service connection goes down
|
||||
// before flutter_tools connects to DDS. The DDS `done` future completes when DDS
|
||||
// shuts down, including after an error. If `done` completes before `connectToVmService`,
|
||||
// something went wrong that caused DDS to shutdown early.
|
||||
try {
|
||||
service = await connectToVmService(
|
||||
disableDds ? observatoryUri : device.dds.uri,
|
||||
reloadSources: reloadSources,
|
||||
restart: restart,
|
||||
compileExpression: compileExpression,
|
||||
reloadMethod: reloadMethod,
|
||||
getSkSLMethod: getSkSLMethod,
|
||||
printStructuredErrorLogMethod: printStructuredErrorLogMethod,
|
||||
device: device,
|
||||
);
|
||||
service = await Future.any<dynamic>(
|
||||
<Future<dynamic>>[
|
||||
connectToVmService(
|
||||
disableDds ? observatoryUri : device.dds.uri,
|
||||
reloadSources: reloadSources,
|
||||
restart: restart,
|
||||
compileExpression: compileExpression,
|
||||
reloadMethod: reloadMethod,
|
||||
getSkSLMethod: getSkSLMethod,
|
||||
printStructuredErrorLogMethod: printStructuredErrorLogMethod,
|
||||
device: device,
|
||||
),
|
||||
device.dds.done.whenComplete(() => throw Exception('DDS shut down too early')),
|
||||
]
|
||||
) as vm_service.VmService;
|
||||
} on Exception catch (exception) {
|
||||
globals.printTrace('Fail to connect to service protocol: $observatoryUri: $exception');
|
||||
if (!completer.isCompleted && !_isListeningForObservatoryUri) {
|
||||
|
||||
Reference in New Issue
Block a user