grpc / grpc-dart

The Dart language implementation of gRPC.
https://pub.dev/packages/grpc
Apache License 2.0
861 stars 271 forks source link

OSError (OS Error: No such host is known. , errno = 11001) #503

Closed MelbourneDeveloper closed 3 years ago

MelbourneDeveloper commented 3 years ago
I have a gRPC service running on Cloud Run over http2. I can easily hit it with a .NET gRPC client, but when I try to hit it with my flutter app running as a Windows app, I get this error: ![image](https://user-images.githubusercontent.com/16697547/125910012-43b98d63-3f96-42d5-bb45-3a881e0c3eb1.png) The code runs fine on Flutter Windows when the host address is `http://localhost:5000` 3.0.0 ## Repro steps Put a gRPC service up somewhere and set it up for http2 with a HTTPS address. Generate the code from the protos and hit the service with this code on a Windows app: ```Dart final channel = ClientChannel( 'https://[URL]/', options: ChannelOptions( credentials: const ChannelCredentials.insecure(), codecRegistry: CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]), )); final client = TheServiceClient(channel); ``` I have tried multiple permutations of options including secure and no options. All have the same result. You should see the error. ## Details This is the code it hits when it gets the exception ```Dart static Future> lookup(String host, {InternetAddressType type: InternetAddressType.any}) { return _IOService._dispatch(_IOService.socketLookup, [host, type._value]) .then((response) { if (isErrorResponse(response)) { throw createError(response, "Failed host lookup: '$host'"); } return [ for (var result in response.skip(1)) _InternetAddress(InternetAddressType._from(result[0]), result[1], host, result[2], result[3]) ]; }); } ``` ![image](https://user-images.githubusercontent.com/16697547/125911363-c2cd68ca-5b34-477e-9ddb-62db856ee07b.png)
mraleph commented 3 years ago

@MelbourneDeveloper please notice that documentation for ClientChannel constructor is quite explicit in saying that the first parameter is host not a uri.

You are looking for something like this:

ClientChannel(
    serverHostname,
    port: serverPort, // if different from defaults
    options: ChannelOptions(
      credentials: const ChannelCredentials.secure(), // to use HTTPS
      codecRegistry:
          CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
    ));
MelbourneDeveloper commented 3 years ago

@mraleph isn't secure the default? I tried without any arguments and it didn't work.

MelbourneDeveloper commented 3 years ago

@mraleph I tried this just now:

  final channel = ClientChannel(
    "https://[URL]",

    options: ChannelOptions(
      credentials: const ChannelCredentials.secure(), // to use HTTPS
      codecRegistry:
          CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
    ));

And, I get the same error.

Note that I have to add this ignore:

// ignore_for_file: avoid_redundant_argument_values

MelbourneDeveloper commented 3 years ago

@mraleph why did you close this? I'm still getting the error despite using your code.

Please reopen, or I will need to create a new issue.

mraleph commented 3 years ago

Oh, yeah. credentials are secure by default. You don't need that.

    "https://[URL]",

But this you need to fix. This parameter should just be a host name as I have said. Not a uri.

MelbourneDeveloper commented 3 years ago

@mraleph got it! Thank. That's awesome.

This parameter should just be a host name as I have said. Not a uri

This is not consistent with other platforms. On .NET you use a uri.

mraleph commented 3 years ago

This is not consistent with other platforms. On .NET you use a uri.

Yeah, we seem to have departed from what is described in https://github.com/grpc/grpc/blob/master/doc/naming.md for unclear reasons. I don't know why, maybe original implementors did not see that document.