From 15c145162cdcbd7467ae296469f27a120a1aa841 Mon Sep 17 00:00:00 2001 From: Ben Konyi Date: Thu, 1 Aug 2024 17:03:51 -0400 Subject: [PATCH] [ DWDS ] Spawn DDS in a process rather than using package:dds (#2466) This is part of the effort to stop shipping DDS via Pub. --- dwds/CHANGELOG.md | 1 + dwds/lib/src/services/debug_service.dart | 15 ++++++++------- dwds/lib/src/utilities/server.dart | 11 ----------- dwds/pubspec.yaml | 2 +- 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index e83dbc16e..d3d913ffa 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -7,6 +7,7 @@ - Hide more variables from the local scope when debugging. These variables were synthetically added by the compiler to support late local variables and don't appear in the original source code. - [#2445](https://github.com/dart-lang/webdev/pull/2445) - Require Dart `^3.4` +- Spawn DDS in a separate process using `dart development-service` instead of launching from `package:dds`. - [#2466](https://github.com/dart-lang/webdev/pull/2466) ## 24.0.0 diff --git a/dwds/lib/src/services/debug_service.dart b/dwds/lib/src/services/debug_service.dart index 23279ac9e..e7fd46492 100644 --- a/dwds/lib/src/services/debug_service.dart +++ b/dwds/lib/src/services/debug_service.dart @@ -8,7 +8,7 @@ import 'dart:io'; import 'dart:math'; import 'dart:typed_data'; -import 'package:dds/dds.dart'; +import 'package:dds/dds_launcher.dart'; import 'package:dwds/src/config/tool_configuration.dart'; import 'package:dwds/src/connections/app_connection.dart'; import 'package:dwds/src/debugging/execution_context.dart'; @@ -27,6 +27,8 @@ import 'package:sse/server/sse_handler.dart'; import 'package:vm_service_interface/vm_service_interface.dart'; import 'package:web_socket_channel/web_socket_channel.dart'; +const _kSseHandlerPath = '\$debugHandler'; + bool _acceptNewConnections = true; int _clientsConnected = 0; @@ -136,7 +138,7 @@ class DebugService { final bool _useSse; final bool _spawnDds; final UrlEncoder? _urlEncoder; - DartDevelopmentService? _dds; + DartDevelopmentServiceLauncher? _dds; /// Null until [close] is called. /// @@ -160,11 +162,11 @@ class DebugService { if (_dds != null) _dds!.shutdown(), ]); - Future startDartDevelopmentService() async { + Future startDartDevelopmentService() async { // Note: DDS can handle both web socket and SSE connections with no // additional configuration. - _dds = await DartDevelopmentService.startDartDevelopmentService( - Uri( + _dds = await DartDevelopmentServiceLauncher.start( + remoteVmServiceUri: Uri( scheme: 'http', host: hostname, port: port, @@ -175,7 +177,6 @@ class DebugService { host: hostname, port: 0, ), - ipv6: await useIPv6ForHost(hostname), ); return _dds!; } @@ -248,7 +249,7 @@ class DebugService { // DDS will always connect to DWDS via web sockets. if (useSse && !spawnDds) { final sseHandler = SseHandler( - Uri.parse('/$authToken/\$debugHandler'), + Uri.parse('/$authToken/$_kSseHandlerPath'), keepAlive: const Duration(seconds: 5), ); handler = sseHandler.handler; diff --git a/dwds/lib/src/utilities/server.dart b/dwds/lib/src/utilities/server.dart index bb442f680..92bd6ab31 100644 --- a/dwds/lib/src/utilities/server.dart +++ b/dwds/lib/src/utilities/server.dart @@ -12,17 +12,6 @@ import 'package:stack_trace/stack_trace.dart'; import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart' as wip; -/// Returns `true` if [hostname] is bound to an IPv6 address. -Future useIPv6ForHost(String hostname) async { - final addresses = await InternetAddress.lookup(hostname); - if (addresses.isEmpty) return false; - final address = addresses.firstWhere( - (a) => a.type == InternetAddressType.IPv6, - orElse: () => addresses.first, - ); - return address.type == InternetAddressType.IPv6; -} - /// Returns a port that is probably, but not definitely, not in use. /// /// This has a built-in race condition: another process may bind this port at diff --git a/dwds/pubspec.yaml b/dwds/pubspec.yaml index d39684cae..77f292bac 100644 --- a/dwds/pubspec.yaml +++ b/dwds/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: built_value: ^8.3.0 collection: ^1.15.0 crypto: ^3.0.2 - dds: ^4.1.0 + dds: ^4.2.5 file: ">=6.1.4 <8.0.0" http: ^1.0.0 http_multi_server: ^3.2.0