grpc-dart icon indicating copy to clipboard operation
grpc-dart copied to clipboard

onConnectionStateChanged is calling all the time when the GRPC server is unreachable

Open wxkly8888 opened this issue 2 years ago • 0 comments

My grpc server is shutdown, when I try to connect to the server, the onConnectionStateChanged listener is called all the time. here are my codes:

channel = ClientChannel(
       "192.168.1.116",
       port: 60230,
       options: ChannelOptions(
          credentials: ChannelCredentials.insecure(),
         codecRegistry:
         CodecRegistry(codecs: const [GzipCodec(), IdentityCodec()]),
       ),
     );
     _cameraClient = CameraOpInterfaceClient(channel);
    channel.onConnectionStateChanged.listen((state) {
      Log().i("grpc:onConnectionStateChanged=" + state.toString());
      notifyStatusChanged();
    }, onError: (err){
      Log().i("grpc:onError occur="+err.toString());

    }, onDone: (){
      Log().i("grpc:ondone called");
    }, cancelOnError: true);

I only called this code once. But It keeps throwing this error, it seems like it keep reconnecting in the background :

2023-04-13 16:40:27.147 26855-26914 flutter E [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: gRPC Error (code: 14, codeName: UNAVAILABLE, message: Error connecting: SocketException: Connection refused (OS Error: Connection refused, errno = 111), address = 192.168.1.116, port = 60230, details: null, rawResponse: null, trailers: {}) then in onConnectionStateChanged callback, I keep receving repeat events:ConnectionState.connecting, ConnectionState.idle... here are the logs:

2023-04-13 16:42:37.345 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:37.408 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:37.458 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:37.520 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:37.576 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:37.637 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:37.705 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:38.585 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:38.627 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:38.701 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:38.741 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:38.800 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:38.853 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:38.904 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:38.947 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:39.006 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:39.051 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:39.113 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:39.158 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m
2023-04-13 16:42:39.222 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.idle[0m
2023-04-13 16:42:39.265 26855-26914 flutter                         I  [38;5;12m│ 💡 grpc:onConnectionStateChanged=ConnectionState.connecting[0m

I am using grpc-3.10

Reproducibility: Always

wxkly8888 avatar Apr 13 '23 08:04 wxkly8888