@@ -156,6 +156,7 @@ Future<void> _run({
156156 SkiaGoldClient ? skiaGoldClient;
157157 late final ServerSocket server;
158158 final List <Future <void >> pendingComparisons = < Future <void >> [];
159+ final List <Socket > pendingConnections = < Socket > [];
159160 await step ('Starting server...' , () async {
160161 server = await ServerSocket .bind (InternetAddress .anyIPv4, _tcpPort);
161162 if (verbose) {
@@ -165,6 +166,7 @@ Future<void> _run({
165166 if (verbose) {
166167 stdout.writeln ('client connected ${client .remoteAddress .address }:${client .remotePort }' );
167168 }
169+ pendingConnections.add (client);
168170 client.transform (const ScreenshotBlobTransformer ()).listen ((Screenshot screenshot) {
169171 final String fileName = screenshot.filename;
170172 final Uint8List fileContent = screenshot.fileContent;
@@ -189,6 +191,8 @@ Future<void> _run({
189191 });
190192 pendingComparisons.add (comparison);
191193 }
194+ }, onDone: () {
195+ pendingConnections.remove (client);
192196 });
193197 });
194198 });
@@ -340,6 +344,9 @@ Future<void> _run({
340344 });
341345 } finally {
342346 await server.close ();
347+ for (final Socket client in pendingConnections.toList ()) {
348+ client.close ();
349+ }
343350
344351 await step ('Killing test app and test runner...' , () async {
345352 final int exitCode = await pm.runAndForward (< String > [adb.path, 'shell' , 'am' , 'force-stop' , 'dev.flutter.scenarios' ]);
0 commit comments