From d7bca62333469651d7b61eb6f3bde3e26972c8e8 Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Fri, 20 Oct 2023 14:52:04 +0200 Subject: [PATCH] Apply 193 (#197) fixes #193 --- packages/custom_lint/CHANGELOG.md | 3 ++ .../lib/src/v2/server_to_client_channel.dart | 39 ++++++++++++------- packages/custom_lint/test/cli_test.dart | 4 +- .../custom_lint_builder/lib/src/channel.dart | 3 +- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/packages/custom_lint/CHANGELOG.md b/packages/custom_lint/CHANGELOG.md index b80706c3..02a3fcb0 100644 --- a/packages/custom_lint/CHANGELOG.md +++ b/packages/custom_lint/CHANGELOG.md @@ -15,6 +15,9 @@ Optimized logic for finding an unused VM_service port. - Sort lints by severity in the command line (thanks to @kuhnroyal) - Fix watch mode not quitting with `q` (thanks to @kuhnroyal) - Improve the command line's output (thanks to @kuhnroyal) +- Update uuid to 4.0.0 +- Fixed a port leak +- Fix connection issues on Docker/windows (thanks to @hamsbrar) ## 0.5.3 - 2023-08-29 diff --git a/packages/custom_lint/lib/src/v2/server_to_client_channel.dart b/packages/custom_lint/lib/src/v2/server_to_client_channel.dart index f51ba237..739c6b08 100644 --- a/packages/custom_lint/lib/src/v2/server_to_client_channel.dart +++ b/packages/custom_lint/lib/src/v2/server_to_client_channel.dart @@ -162,20 +162,27 @@ class SocketCustomLintServerToClientChannel { _tempDirectory = await _workspace.createPluginHostDirectory(); _writeEntrypoint(_workspace.uniquePluginNames, tempDirectory); - return _asyncRetry(retryCount: 5, () async { - // Using "late" to fetch the port only if needed (in watch mode) - late final port = _findPossiblyUnusedPort(); - final process = await Process.start( - Platform.resolvedExecutable, - [ - if (_server.watchMode) '--enable-vm-service=${await port}', - join('lib', 'custom_lint_client.dart'), - _serverSocket.port.toString(), - ], - workingDirectory: tempDirectory.path, - ); - return process; - }); + try { + return _asyncRetry(retryCount: 5, () async { + // Using "late" to fetch the port only if needed (in watch mode) + late final port = _findPossiblyUnusedPort(); + final process = await Process.start( + Platform.resolvedExecutable, + [ + if (_server.watchMode) '--enable-vm-service=${await port}', + join('lib', 'custom_lint_client.dart'), + _serverSocket.address.host, + _serverSocket.port.toString(), + ], + workingDirectory: tempDirectory.path, + ); + return process; + }); + } catch (_) { + // If the process failed to start, we can delete the temp directory + await _tempDirectory?.delete(recursive: true); + rethrow; + } } void _writeEntrypoint( @@ -201,10 +208,12 @@ import 'package:custom_lint_builder/src/channel.dart'; $imports void main(List args) async { - final port = int.parse(args.single); + final host = args[0]; + final port = int.parse(args[1]); runSocket( port: port, + host: host, includeBuiltInLints: ${_server.includeBuiltInLints}, {$plugins}, ); diff --git a/packages/custom_lint/test/cli_test.dart b/packages/custom_lint/test/cli_test.dart index 37ce2c16..366e1939 100644 --- a/packages/custom_lint/test/cli_test.dart +++ b/packages/custom_lint/test/cli_test.dart @@ -243,7 +243,7 @@ invalid; ^^^^^^^ '''), matchIgnoringAnsi(contains, ''' -lib/custom_lint_client.dart:13:29: Error: Undefined name 'createPlugin'. +lib/custom_lint_client.dart:15:29: Error: Undefined name 'createPlugin'. {'test_lint': test_lint.createPlugin, ^^^^^^^^^^^^ '''), @@ -362,7 +362,7 @@ int x = 'oy'; ^ '''), matchIgnoringAnsi(contains, ''' -lib/custom_lint_client.dart:15:26: Error: Undefined name 'createPlugin'. +lib/custom_lint_client.dart:17:26: Error: Undefined name 'createPlugin'. 'test_lint2': test_lint2.createPlugin, ^^^^^^^^^^^^ '''), diff --git a/packages/custom_lint_builder/lib/src/channel.dart b/packages/custom_lint_builder/lib/src/channel.dart index 8c87089a..ba97835f 100644 --- a/packages/custom_lint_builder/lib/src/channel.dart +++ b/packages/custom_lint_builder/lib/src/channel.dart @@ -57,6 +57,7 @@ typedef CreatePluginMain = PluginBase Function(); Future runSocket( Map pluginMains, { required int port, + required String host, required bool includeBuiltInLints, }) async { late Future client; @@ -64,7 +65,7 @@ Future runSocket( await asyncRunZonedGuarded( () => client = Future(() async { // ignore: close_sinks, connection stays open until the plugin is killed - final socket = await Socket.connect('localhost', port); + final socket = await Socket.connect(host, port); final socketChannel = JsonSocketChannel(Future.value(socket)); final registeredPlugins = {};