Reland "[DDS] Make runDartDevelopmentServiceFromCLI use IPv6 to serve DDS if either the VM Service address or the bind address cannot be resolved to an IPv4 address"
This is a reland of commit 4391ca6643b67688ae1bfdedafc7e054833af4e7
I have verified that internal CL 687283510 will permit this change to
land without issue.
Original change's description:
> [DDS] Make runDartDevelopmentServiceFromCLI use IPv6 to serve DDS if either the VM Service address or the bind address cannot be resolved to an IPv4 address
>
> TEST=CI
>
> Fixes: https://github.com/dart-lang/sdk/issues/56557
> Change-Id: Id06532aedf26d8d5e4d037df72dece2d6550e694
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389521
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Derek Xu <derekx@google.com>
Change-Id: Ib7536f61d49526e67d449ca0a475f379ad4bd362
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390760
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
diff --git a/pkg/dds/lib/src/dds_cli_entrypoint.dart b/pkg/dds/lib/src/dds_cli_entrypoint.dart
index 9fca824..f02b766 100644
--- a/pkg/dds/lib/src/dds_cli_entrypoint.dart
+++ b/pkg/dds/lib/src/dds_cli_entrypoint.dart
@@ -49,18 +49,33 @@
return;
}
- // This URI is provided by the VM service directly so don't bother doing a
- // lookup.
+ // Check if the remote VM Service address can be resolved to an IPv4 address.
final remoteVmServiceUri = Uri.parse(
argResults[DartDevelopmentServiceOptions.vmServiceUriOption],
);
+ bool doesVmServiceAddressResolveToIpv4Address = false;
+ try {
+ final addresses = await InternetAddress.lookup(remoteVmServiceUri.host);
+ for (final address in addresses) {
+ if (address.type == InternetAddressType.IPv4) {
+ doesVmServiceAddressResolveToIpv4Address = true;
+ }
+ }
+ } on SocketException catch (e, st) {
+ writeErrorResponse(
+ 'Invalid --${DartDevelopmentServiceOptions.vmServiceUriOption} argument: '
+ '$remoteVmServiceUri',
+ st,
+ );
+ return;
+ }
// Ensure that the bind address, which is potentially provided by the user,
// can be resolved at all, and check whether it can be resolved to an IPv4
// address.
- bool doesBindAddressResolveToIpv4Address = false;
final bindAddress =
argResults[DartDevelopmentServiceOptions.bindAddressOption];
+ bool doesBindAddressResolveToIpv4Address = false;
try {
final addresses = await InternetAddress.lookup(bindAddress);
for (final address in addresses) {
@@ -115,9 +130,10 @@
remoteVmServiceUri,
serviceUri: serviceUri,
enableAuthCodes: !disableServiceAuthCodes,
- // Only use IPv6 to serve DDS if the bind address cannot be resolved to an
- // IPv4 address.
- ipv6: !doesBindAddressResolveToIpv4Address,
+ // Only use IPv6 to serve DDS if either the remote VM Service address or
+ // the bind address cannot be resolved to an IPv4 address.
+ ipv6: !doesVmServiceAddressResolveToIpv4Address ||
+ !doesBindAddressResolveToIpv4Address,
devToolsConfiguration: serveDevTools && devToolsBuildDirectory != null
? DevToolsConfiguration(
enable: serveDevTools,
diff --git a/pkg/dds/test/dap/integration/debug_attach_test.dart b/pkg/dds/test/dap/integration/debug_attach_test.dart
index 172e814..707214e 100644
--- a/pkg/dds/test/dap/integration/debug_attach_test.dart
+++ b/pkg/dds/test/dap/integration/debug_attach_test.dart
@@ -128,10 +128,7 @@
expect(
outputEvents.map((e) => e.output).join(),
- allOf(
- contains('Failed to start DDS for ws://bogus.local/'),
- contains('Failed host lookup'),
- ),
+ contains('Invalid --vm-service-uri argument: http://bogus.local'),
);
});