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

Connection timed out on OS that doesn't support binding to IPv6 addresses. #193

Closed
hamsbrar opened this issue Oct 7, 2023 · 2 comments · Fixed by #197
Closed

Connection timed out on OS that doesn't support binding to IPv6 addresses. #193

hamsbrar opened this issue Oct 7, 2023 · 2 comments · Fixed by #197

Comments

@hamsbrar
Copy link

hamsbrar commented Oct 7, 2023

Trying to use it inside a linux box that doesn't support IPv6 stack.

From what I can find,

final socket = await Socket.connect(InternetAddress.loopbackIPv6, port);

This fails when server is using a IPv4 socket.

No idea how rest of the system is structured or how Socket.connect(InternetAddress.loopbackIPv6 is implemented but in general, I'd use IPv4 everywhere. If v6 required, I'd first check whether server supports it, then use with v6_only=false (if I can afford dual stack sockets but not multiple ports), else with v6_only=true (even when =false is supported) and create two sockets (for peace of mind), and then propagate that information to every relavant parts including clients so they can connect according to their capabilities, without running into repeated timeouts.

Quick way would be to pass host to clients so they don't have to guess it:

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 47acdfd..918a717 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
@@ -173,6 +173,7 @@ class SocketCustomLintServerToClientChannel {
           [
             if (_server.watchMode) '--enable-vm-service=${await port}',
             join('lib', 'custom_lint_client.dart'),
+            _serverSocket.address.host,
             _serverSocket.port.toString(),
           ],
           workingDirectory: tempDir.path,
@@ -209,10 +210,12 @@ import 'package:custom_lint_builder/src/channel.dart';
 $imports
 
 void main(List<String> 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_builder/lib/src/channel.dart b/packages/custom_lint_builder/lib/src/channel.dart
index 98cf7df..b545406 100644
--- a/packages/custom_lint_builder/lib/src/channel.dart
+++ b/packages/custom_lint_builder/lib/src/channel.dart
@@ -56,6 +56,7 @@ typedef CreatePluginMain = PluginBase Function();
 /// Starts a custom_lint client using web sockets.
 Future<void> runSocket(
   Map<String, CreatePluginMain> pluginMains, {
+  required String host,
   required int port,
   required bool includeBuiltInLints,
 }) async {
@@ -64,7 +65,7 @@ Future<void> runSocket(
   await asyncRunZonedGuarded(
     () => client = Future(() async {
       // ignore: close_sinks, connection stays open until the plugin is killed
-      final socket = await Socket.connect(InternetAddress.loopbackIPv6, port);
+      final socket = await Socket.connect(host, port);
       final socketChannel = JsonSocketChannel(Future.value(socket));
       final registeredPlugins = <String, PluginBase>{};

This works for me. Probably related to #115.

Sserra90 pushed a commit to Sserra90/dart_custom_lint that referenced this issue Oct 9, 2023
@Sserra90
Copy link

I had this problem running it inside a linux host on a docker container, the only solution was to fork and apply this patch. It now works both locally and on the CI

@rrousselGit
Copy link
Collaborator

That's an interesting idea.

rrousselGit added a commit that referenced this issue Oct 20, 2023
@rrousselGit rrousselGit mentioned this issue Oct 20, 2023
rrousselGit added a commit that referenced this issue Oct 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
fixes #193
oskar-zeinomahmalat-sonarsource pushed a commit to oskar-zeinomahmalat-sonarsource/dart_custom_lint that referenced this issue Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants