Skip to content

Commit

Permalink
Automatically pick up unused port (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrousselGit authored Oct 30, 2023
1 parent 8f54a2a commit 331da18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
4 changes: 4 additions & 0 deletions packages/custom_lint/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased patch

Optimized logic for finding an unused VM_service port.

## 0.5.5 - 2023-10-26

- Support `hotreloader` 4.0.0
Expand Down
13 changes: 1 addition & 12 deletions packages/custom_lint/lib/src/v2/server_to_client_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import '../workspace.dart';
import 'custom_lint_analyzer_plugin.dart';
import 'protocol.dart';

Future<int> _findPossiblyUnusedPort() {
return SocketCustomLintServerToClientChannel._createServerSocket()
.then((value) {
final port = value.port;
value.close();
return port;
});
}

Future<T> _asyncRetry<T>(
Future<T> Function() cb, {
required int retryCount,
Expand Down Expand Up @@ -170,12 +161,10 @@ class SocketCustomLintServerToClientChannel {
_writeEntrypoint(_workspace.uniquePluginNames, tempDir);

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}',
if (_server.watchMode) '--enable-vm-service=0',
join('lib', 'custom_lint_client.dart'),
_serverSocket.address.host,
_serverSocket.port.toString(),
Expand Down

1 comment on commit 331da18

@vercel
Copy link

@vercel vercel bot commented on 331da18 Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.