zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 620 forks source link

ValueStreamError: ValueStream has no value. #1259

Open davidpanic opened 1 year ago

davidpanic commented 1 year ago

Describe the issue Sometimes when running connectOrReconnect on a websocket link instance it throws an exception. I think it happens if you call it too fast - before it has a chance to initialize.

To Reproduce

  1. call WebSocketLink.connectOrReconnect() (not exactly sure what the required timing is)

Expected behavior I expect the function to cleanly reconnect the link.

device / execution context iOS 15.6.1 on an iPhone 11 Pro Max.

Other useful/optional fields

Stacktrace: ```dart ValueStreamError: ValueStream has no value. You should check ValueStream.hasValue before accessing ValueStream.value, or use ValueStream.valueOrNull instead. File "behavior_subject.dart", line 146, in BehaviorSubject.value File "websocket_client.dart", line 251, in SocketClient._closeSocketChannel File "websocket_client.dart", line 393, in SocketClient.dispose File "websocket_link.dart", line 40, in WebSocketLink.connectOrReconnect ```

additional context

orestesgaolin commented 1 year ago

Started having the same issue, popping more often than I anticipated

I tried to wrap this with try-catch, but the Future.wait in the dispose() does not have an error handler, so the error is captured by the zone.

 /// Connects or reconnects to the server with the specified headers.
  void _connectOrReconnect(String token) {
    try {
      _connection?.client.dispose();
    } catch (e, s) {
      _log.e('Error closing connection', e, s);
    }

    _connection = _Connection(
...
    );
  }

CleanShot 2022-11-24 at 09 02 55

davidpanic commented 8 months ago

Will this be fixed? It's kind of a bummer to have errors that can't even be handled because of the missing await...