Skip to content

Commit 4391ca6

Browse files
derekxu16Commit Queue
authored andcommitted
[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: #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>
1 parent 3d56a42 commit 4391ca6

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

pkg/dds/lib/src/dds_cli_entrypoint.dart

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,33 @@ ${argParser.usage}
4949
return;
5050
}
5151

52-
// This URI is provided by the VM service directly so don't bother doing a
53-
// lookup.
52+
// Check if the remote VM Service address can be resolved to an IPv4 address.
5453
final remoteVmServiceUri = Uri.parse(
5554
argResults[DartDevelopmentServiceOptions.vmServiceUriOption],
5655
);
56+
bool doesVmServiceAddressResolveToIpv4Address = false;
57+
try {
58+
final addresses = await InternetAddress.lookup(remoteVmServiceUri.host);
59+
for (final address in addresses) {
60+
if (address.type == InternetAddressType.IPv4) {
61+
doesVmServiceAddressResolveToIpv4Address = true;
62+
}
63+
}
64+
} on SocketException catch (e, st) {
65+
writeErrorResponse(
66+
'Invalid --${DartDevelopmentServiceOptions.vmServiceUriOption} argument: '
67+
'$remoteVmServiceUri',
68+
st,
69+
);
70+
return;
71+
}
5772

5873
// Ensure that the bind address, which is potentially provided by the user,
5974
// can be resolved at all, and check whether it can be resolved to an IPv4
6075
// address.
61-
bool doesBindAddressResolveToIpv4Address = false;
6276
final bindAddress =
6377
argResults[DartDevelopmentServiceOptions.bindAddressOption];
78+
bool doesBindAddressResolveToIpv4Address = false;
6479
try {
6580
final addresses = await InternetAddress.lookup(bindAddress);
6681
for (final address in addresses) {
@@ -115,9 +130,10 @@ ${argParser.usage}
115130
remoteVmServiceUri,
116131
serviceUri: serviceUri,
117132
enableAuthCodes: !disableServiceAuthCodes,
118-
// Only use IPv6 to serve DDS if the bind address cannot be resolved to an
119-
// IPv4 address.
120-
ipv6: !doesBindAddressResolveToIpv4Address,
133+
// Only use IPv6 to serve DDS if either the remote VM Service address or
134+
// the bind address cannot be resolved to an IPv4 address.
135+
ipv6: !doesVmServiceAddressResolveToIpv4Address ||
136+
!doesBindAddressResolveToIpv4Address,
121137
devToolsConfiguration: serveDevTools && devToolsBuildDirectory != null
122138
? DevToolsConfiguration(
123139
enable: serveDevTools,

pkg/dds/test/dap/integration/debug_attach_test.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,7 @@ main() {
128128

129129
expect(
130130
outputEvents.map((e) => e.output).join(),
131-
allOf(
132-
contains('Failed to start DDS for ws://bogus.local/'),
133-
contains('Failed host lookup'),
134-
),
131+
contains('Invalid --vm-service-uri argument: http://bogus.local'),
135132
);
136133
});
137134

0 commit comments

Comments
 (0)