Skip to content

Commit

Permalink
[ DWDS ] Spawn DDS in a process rather than using package:dds (#2466)
Browse files Browse the repository at this point in the history
This is part of the effort to stop shipping DDS via Pub.
  • Loading branch information
bkonyi authored Aug 1, 2024
1 parent f0ae463 commit 15c1451
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 19 deletions.
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 8 additions & 7 deletions dwds/lib/src/services/debug_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;

Expand Down Expand Up @@ -136,7 +138,7 @@ class DebugService {
final bool _useSse;
final bool _spawnDds;
final UrlEncoder? _urlEncoder;
DartDevelopmentService? _dds;
DartDevelopmentServiceLauncher? _dds;

/// Null until [close] is called.
///
Expand All @@ -160,11 +162,11 @@ class DebugService {
if (_dds != null) _dds!.shutdown(),
]);

Future<DartDevelopmentService> startDartDevelopmentService() async {
Future<DartDevelopmentServiceLauncher> 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,
Expand All @@ -175,7 +177,6 @@ class DebugService {
host: hostname,
port: 0,
),
ipv6: await useIPv6ForHost(hostname),
);
return _dds!;
}
Expand Down Expand Up @@ -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;
Expand Down
11 changes: 0 additions & 11 deletions dwds/lib/src/utilities/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> 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
Expand Down
2 changes: 1 addition & 1 deletion dwds/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 15c1451

Please sign in to comment.