Skip to content

Commit 1e47b49

Browse files
[ DWDS ] Write to WebkitDebugger.onClose if the debugger connection closes and the attempts to reconnect fail (#2785)
The Flutter tool expects DebugConnection.onDone to complete if the user exits the browser and the debugger connection closes. After receiving notification of a closed connection, WebkitDebugger tries to reconnect to the debugger. If these attempts fail, WebkitDebugger will now write to its onClose stream so that DebugConnection will know to signal onDone. See flutter/flutter#182897
1 parent fde4cdf commit 1e47b49

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎dwds/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Fix serialization of `HotRestartRequest` in `AppConnection`.
1313
- Split integration tests across DDC module systems.
1414
- Split additional tests across DDC module systems.
15+
- Fix issue where `DebugConnection` did not complete `onDone` if `WebkitDebugger` fails to reconnect to the debugger after the connection closes.
1516

1617
## 27.0.0
1718
- Remove `package:built_value`, `package:built_value_generator`, and `package:built_collection` dependencies.

‎dwds/lib/src/debugging/webkit_debugger.dart‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,7 @@ class WebkitDebugger implements RemoteDebugger {
6969
await sub.cancel();
7070
if (_closed != null) {
7171
// The connection closing is expected.
72-
_onClosedController.add(connection);
73-
await Future.wait([
74-
for (final controller in _controllers) controller.close(),
75-
for (final MapEntry(value: (:controller, transformer: _))
76-
in _eventStreams.entries)
77-
controller.close(),
78-
]);
72+
await _shutdown(connection);
7973
return;
8074
}
8175
var retry = false;
@@ -94,7 +88,11 @@ class WebkitDebugger implements RemoteDebugger {
9488
retryCount++;
9589
}
9690
} while (retry && retryCount <= maxAttempts);
97-
_initialize();
91+
if (retryCount > maxAttempts) {
92+
await _shutdown(connection);
93+
} else {
94+
_initialize();
95+
}
9896
});
9997

10098
final runtime = _wipDebugger.connection.runtime;
@@ -125,6 +123,16 @@ class WebkitDebugger implements RemoteDebugger {
125123
]);
126124
}
127125

126+
Future<void> _shutdown(WipConnection connection) async {
127+
_onClosedController.add(connection);
128+
await Future.wait([
129+
for (final controller in _controllers) controller.close(),
130+
for (final MapEntry(value: (:controller, transformer: _))
131+
in _eventStreams.entries)
132+
controller.close(),
133+
]);
134+
}
135+
128136
@override
129137
Stream<ConsoleAPIEvent> get onConsoleAPICalled =>
130138
_onConsoleAPICalledController.stream;

0 commit comments

Comments
 (0)