GetStream / stream-chat-flutter

Flutter Chat SDK - Build your own chat app experience using Dart, Flutter and the Stream Chat Messaging API.
https://getstream.io/chat/sdk/flutter/
Other
880 stars 313 forks source link

StreamChatPersistenceClient hasn't been connected yet or used after `disconnect` was called. #1933

Open sgowda97 opened 3 weeks ago

sgowda97 commented 3 weeks ago

Which packages are you using?

stream_chat_flutter, stream_chat_persistance

On what platforms did you experience the issue?

Android

What version are you using?

7.2.0-hotfix.1

What happened?

StreamChatPersistenceClient.updateConnectionInfo() is being called periodically even after calling StreamChatClient.dispose(), which is leading to an error as provided in the logs below.

Expected: All forms of chatClient and persistenceClient should be disposed on calling dispose().

Steps to reproduce

I am calling StreamChatClient.dispose() on firebase logout.

Supporting info to reproduce

final chatPersistentClient = StreamChatPersistenceClient(
    logLevel: Level.SEVERE,
    connectionMode: ConnectionMode.regular,
);

late StreamChatClient client;

Future<void> init({required String apiKey}) async {
    client = StreamChatClient(
      apiKey,
      logLevel: kDebugMode ? Level.INFO : Level.SEVERE,
    )..chatPersistenceClient = chatPersistentClient;
}
Future<void> close() async {
    await client.dispose();
}

Relevant log output

I/flutter ( 9985): 2024-06-04 10:58:28.510378 ℹ️ 📡 Closing web-socket connection for SHR505191641 
I/flutter ( 9985): 2024-06-04 10:59:00.100214 ℹ️ 🔌 Disconnecting web-socket connection 
I/flutter ( 9985): 2024-06-04 10:59:14.214515 ℹ️ 🔌 Stopped monitoring events 
I/flutter ( 9985): 2024-06-04 10:59:17.926247 ℹ️ 🔌 Closing connection with https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 10:59:17.931451 ℹ️ 🔌 Stopped listening to https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 10:59:24.304185 ℹ️ (I/SV:Client): [disconnect] currentUser.id: SHR505191641
I/flutter ( 9985): 2024-06-04 10:59:27.232871 ℹ️ (I/SV:CoordClient): [closeConnection] no args
I/flutter ( 9985): 2024-06-04 10:59:27.239582 ℹ️ (I/SV:CoordinatorWS-1): [disconnect] closeCode: "null", closeReason: "null"
I/flutter ( 9985): 2024-06-04 10:59:27.358198 ℹ️ (I/SV:CoordinatorWS-1): [disconnect] connectRequestInProgress: false, url: wss://video.stream-io-api.com/video/connect?api_key=[KEY]&stream-auth-type=jwt&X-Stream-Client=stream-video-dart-client-android-0.3.9
I/flutter ( 9985): 2024-06-04 10:59:28.635399 ℹ️ (I/SV:LifecycleUtilsM): [appState] cancelled
W/Firestore( 9985): (24.11.0) [WatchStream]: (382f4e8) Stream closed with status: Status{code=CANCELLED, description=Disconnecting idle stream. Timed out waiting for new targets., cause=null}.
I/flutter ( 9985): 2024-06-04 10:59:48.392815 ℹ️ (I/SV:Client): [disconnect] clear shared operation
I/flutter ( 9985): 2024-06-04 10:59:53.965019 ℹ️ (I/SV:Client): [dispose]

I/flutter ( 9985): 2024-06-04 11:00:33.567154 ℹ️ 🔌 Sending Event: health.check 
I/flutter ( 9985): 2024-06-04 11:00:33.575853 ℹ️ 🔌 Needs to reconnect : true 
I/flutter ( 9985): 2024-06-04 11:00:33.582929 ℹ️ 🔌 Retrying connection : 0 
I/flutter ( 9985): 2024-06-04 11:00:33.584812 ℹ️ 🔌 Stopped monitoring events 
I/flutter ( 9985): 2024-06-04 11:00:33.585206 ℹ️ 🔌 Closing connection with https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 11:00:33.586387 ℹ️ 🔌 Stopped listening to https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 11:00:33.593519 ℹ️ 🔌 Needs to reconnect : true 
I/flutter ( 9985): 2024-06-04 11:00:33.595293 ℹ️ 🔌 Retrying connection : 0 
I/flutter ( 9985): 2024-06-04 11:00:33.595611 ℹ️ 🔌 Stopped monitoring events 
I/flutter ( 9985): 2024-06-04 11:00:33.595865 ℹ️ 🔌 Closing connection with https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 11:00:33.596753 ℹ️ 🔌 Stopped listening to https://chat.stream-io-api.com 

I/flutter ( 9985): 2024-06-04 11:00:34.940031 ℹ️ 🔌 Initiating connection with https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 11:00:34.954523 ℹ️ 🔌 Started listening to https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 11:00:35.260602 ℹ️ 🔌 Initiating connection with https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 11:00:35.263002 ℹ️ 🔌 Started listening to https://chat.stream-io-api.com 
I/flutter ( 9985): 2024-06-04 11:00:35.301074 ℹ️ 🔌 Event received: health.check 
I/flutter ( 9985): 2024-06-04 11:00:35.302405 ℹ️ 🔌 Connection successful: 65e9ed49-0a09-324a-0000-000001cf8435 
I/flutter ( 9985): 2024-06-04 11:00:35.302772 ℹ️ 🔌 Starting monitoring events 
I/flutter ( 9985): 2024-06-04 11:00:35.303467 ℹ️ 🔌 Starting health check monitor 
I/flutter ( 9985): 2024-06-04 11:00:35.312460 ℹ️ 🔌 Sending Event: health.check 
I/flutter ( 9985): 2024-06-04 11:00:35.321707 ℹ️ 🔌 Starting reconnection monitor 
I/flutter ( 9985): 2024-06-04 11:00:35.324026 ℹ️ 🔌 Needs to reconnect : false

E/flutter ( 9985): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Bad state:         StreamChatPersistenceClient hasn't been connected yet or used after `disconnect` 
E/flutter ( 9985):         was called. Consider calling `connect` to create a connection. 
E/flutter ( 9985):           
E/flutter ( 9985): #0      StreamChatPersistenceClient._debugIsConnected.<anonymous closure> (package:stream_chat_persistence/src/stream_chat_persistence_client.dart:62:9)
E/flutter ( 9985): #1      StreamChatPersistenceClient._debugIsConnected (package:stream_chat_persistence/src/stream_chat_persistence_client.dart:68:6)
E/flutter ( 9985): #2      StreamChatPersistenceClient.updateConnectionInfo (package:stream_chat_persistence/src/stream_chat_persistence_client.dart:113:12)
E/flutter ( 9985): #3      StreamChatClient._handleHealthCheckEvent (package:stream_chat/src/client/client.dart:462:30)
E/flutter ( 9985): #4      StreamChatClient.handleEvent (package:stream_chat/src/client/client.dart:469:14)
E/flutter ( 9985): #5      WebSocket._onDataReceived (package:stream_chat/src/ws/websocket.dart:349:21)
E/flutter ( 9985): #6      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter ( 9985): #7      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 9985): #8      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter ( 9985): #9      _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123:11)
E/flutter ( 9985): #10     _HandleErrorStream._handleData (dart:async/stream_pipe.dart:253:10)
E/flutter ( 9985): #11     _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153:13)
E/flutter ( 9985): #12     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter ( 9985): #13     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 9985): #14     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter ( 9985): #15     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter ( 9985): #16     _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter ( 9985): #17     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter ( 9985): #18     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 9985): #19     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter ( 9985): #20     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter ( 9985): #21     _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter ( 9985): #22     _StreamController.add (dart:async/stream_controller.dart:606:5)
E/flutter ( 9985): #23     new _WebSocketImpl._fromSocket.<anonymous closure> (dart:_http/websocket_impl.dart:1144:21)
E/flutter ( 9985): #24     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter ( 9985): #25     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 9985): #26     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter ( 9985): #27     _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
E/flutter ( 9985): #28     _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
E/flutter ( 9985): #29     _WebSocketProtocolTransformer._messageFrameEnd (dart:_http/websocket_impl.dart:332:23)
E/flutter ( 9985): #30     _WebSocketProtocolTransformer.add (dart:_http/websocket_impl.dart:226:46)
E/flutter ( 9985): #31     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
E/flutter ( 9985): #32     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter ( 9985): #33     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 9985): #34     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter ( 9985): #35     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter ( 9985): #36     _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter ( 9985): #37     _StreamController.add (dart:async/stream_controller.dart:606:5)
E/flutter ( 9985): #38     _Socket._onData (dart:io-patch/socket_patch.dart:2447:41)
E/flutter ( 9985): #39     _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
E/flutter ( 9985): #40     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter ( 9985): #41     _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
E/flutter ( 9985): #42     _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:784:19)
E/flutter ( 9985): #43     _StreamController._add (dart:async/stream_controller.dart:658:7)
E/flutter ( 9985): #44     _StreamController.add (dart:async/stream_controller.dart:606:5)
E/flutter ( 9985): #45     _RawSecureSocket._sendReadEvent (dart:io/secure_socket.dart:1116:19)
E/flutter ( 9985): #46     Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter ( 9985): #47     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter ( 9985): #48     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter ( 9985): #49     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Flutter analyze output

No response

Flutter doctor output

No response

Code of Conduct

github-actions[bot] commented 1 day ago

This issue is stale because it has been open for 20 days with no activity.