Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically pick up unused port #202

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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