ConnectyCube / connectycube-flutter-sdk-releases

ConnectyCube Flutter SDK Releases
7 stars 1 forks source link

CubeChatConnection.instance.destroy() doesn't dispose of all managers properly #8

Closed DDavidPrime closed 4 years ago

DDavidPrime commented 4 years ago

Hi there.

I was using your package and noticed that when using the chat some of the managers inside CubeChatConnection.instance get initialized while you use them and others don't (they keep the null value). This may not be a problem, but the issue arises when you use the CubeChatConnection.instance.destroy() method. In this case, the _closeManager(manager); will fail at the first null value and throw an error, preventing the other managers to be closed afterwards.

My suggestion is to do a null check before closing the manager as this will fix the problem.

Edit: After debugging I noticed that after calling _closeManager(); inside the destroy() method, even though the manager was closed, it's reference is still not set to null.

Steps to reproduce:

  1. Log in with a user session
  2. Log out using user using the following code
    signOut().then(
    (_){
      CubeChatConnection.instance.logout();
      CubeChatConnection.instance.destroy(); // This is what throws an error
    },
    )

Additional Info: While debugging, I placed a breakpoint on CubeChatConnection.instance.destroy() in the previous code. Stepping into that method and examining line by line, I eventually got to the line _closeManager(_privateChatManager); which threw an exception, because _privateChatManager was null. Because of that, the execution of the method didn't continue, so other manager didn't get closed. Additionally, in another scenario, where _privateChatManager was not null, _closeManager method did close it, but it's value wasn't set to null afterwards.

Logs:

Click to expand/collapse
I don't think there are any errors logged, but here's the log anyway:

``` I/flutter (21949): login with usr1 and 12345678 I/flutter (21949): CB-SDK: : ========================================================= I/flutter (21949): === REQUEST ==== 1b4e7bb3-3095-458e-8ef2-f21ccfc201f0 === I/flutter (21949): REQUEST I/flutter (21949): POST https://api.connectycube.com/session I/flutter (21949): HEADERS I/flutter (21949): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 0.4.0, CB-Token: } I/flutter (21949): BODY I/flutter (21949): {"application_id":"476","auth_key":"PDZjPBzAO8WPfCp","nonce":"1795023071","timestamp":"1599472578","signature":"a3a87d5e24c42732b42b80fa334b18b358d1f324","user":{"login":"usr1","password":"12345678"}} I/flutter (21949): I/flutter (21949): CB-SDK: : ********************************************************* I/flutter (21949): *** RESPONSE *** 201 *** 1b4e7bb3-3095-458e-8ef2-f21ccfc201f0 *** I/flutter (21949): HEADERS I/flutter (21949): {connection: keep-alive, cache-control: max-age=0, private, must-revalidate, set-cookie: _mkra_ctxt=4a0c83452f59cfa275ba9dc2fa65a123--201; path=/; max-age=5; HttpOnly; secure, status: 201 Created, transfer-encoding: chunked, date: Mon, 07 Sep 2020 09:56:21 GMT, access-control-allow-origin: *, strict-transport-security: max-age=31536000,max-age=15768000;, content-type: application/json; charset=utf-8, x-xss-protection: 1; mode=block, server: nginx/1.16.1, x-request-id: 92a7b48f-ad11-4bfa-a7ba-cb1c00277351, cb-token-expirationdate: 2020-09-07 11:56:21 UTC, connectycube-rest-api-version: 0.1.1, x-runtime: 0.038022, etag: W/"6796b6f55063f3520a54dcbf0261d934", x-frame-options: SAMEORIGIN, x-content-type-options: nosniff} I/flutter (21949): BODY I/flutter (21949): {"session":{"id":16826016,"user_id":1890491,"application_id":476,"nonce":1795023071,"token":"315b34b90e8b290ac653bc276a3741406e0001dc","ts":1599472578,"created_at":"2020-09-07T09:56:21Z","updated_at":"2020-09-07T09:56:21Z","user":{"id":1890491,"full_name":"usr1","email":null,"login":"usr1","phone":null,"website":null,"created_at":"2020-09-07T09:17:12Z","updated_at":"2020-09-07T09:56:21Z","last_request_at":"2020-09-07T09:56:21Z","external_user_id":null,"facebook_id":null,"twitter_id":null,"blob_id":null,"custom_data":null,"avatar":null,"user_tags":null}}} I/flutter (21949): I/flutter (21949): _loginToCubeChat user {full_name: usr1, email: null, login: usr1, phone: null, website: null, last_request_at: 2020-09-07 09:56:21.000Z, external_user_id: null, facebook_id: null, twitter_id: null, password: 12345678, oldPassword: null, custom_data: null, avatar: null, tag_list: null, id: 1890491, created_at: 2020-09-07 09:17:12.000Z, updated_at: 2020-09-07 09:56:21.000Z} I/flutter (21949): sending: I/flutter (21949): I/flutter (21949): State: XmppConnectionState.SocketOpening I/flutter (21949): CB-SDK: CubeChatConnection: Chat connection SocketOpening I/flutter (21949): response: I/flutter (21949): processInitialStream I/flutter (21949): response: PLAINANONYMOUSPLAIN_FASTzlib I/flutter (21949): Negotating features I/flutter (21949): ELEMENT true I/flutter (21949): negotiating starttls I/flutter (21949): sending: I/flutter (21949): Feature Started Parsing I/flutter (21949): response: I/flutter (21949): startSecureSocket I/flutter (21949): XmppConnectionState.SocketOpening I/flutter (21949): sending: I/flutter (21949): I/flutter (21949): response: I/flutter (21949): processInitialStream I/flutter (21949): response: PLAINANONYMOUSPLAIN_FASTzlib I/flutter (21949): Negotating features I/flutter (21949): ELEMENT true I/flutter (21949): sending: ADE4OTA0OTEtNDc2ADEyMzQ1Njc4 I/flutter (21949): Feature Started Parsing I/flutter (21949): response: I/flutter (21949): sending: I/flutter (21949): I/flutter (21949): State: XmppConnectionState.Authenticated I/flutter (21949): CB-SDK: CubeChatConnection: Chat connection Authenticated I/flutter (21949): ELEMENT true I/flutter (21949): sending: I/flutter (21949): Feature Started Parsing I/flutter (21949): response: I/flutter (21949): processInitialStream I/flutter (21949): response: I/flutter (21949): DONE PARSING FATURES I/flutter (21949): State: XmppConnectionState.DoneParsingFeatures I/flutter (21949): CB-SDK: CubeChatConnection: Chat connection DoneParsingFeatures I/flutter (21949): response: zlib I/flutter (21949): Negotating features I/flutter (21949): ELEMENT true I/flutter (21949): sending: I/flutter (21949): I/flutter (21949): flutter_4f41f6be2c5b6aff I/flutter (21949): I/flutter (21949): I/flutter (21949): Feature Started Parsing I/flutter (21949): response: I/flutter (21949): sending: I/flutter (21949): response: 1890491-476@chat.connectycube.com/flutter_4f41f6be2c5b6aff I/flutter (21949): ELEMENT false I/flutter (21949): ELEMENT true I/flutter (21949): sending: I/flutter (21949): I/flutter (21949): I/flutter (21949): Feature Started Parsing I/flutter (21949): response: I/flutter (21949): sending: I/flutter (21949): response: I/flutter (21949): State: XmppConnectionState.SessionInitialized I/flutter (21949): CB-SDK: CubeChatConnection: Chat connection SessionInitialized I/flutter (21949): sending: I/flutter (21949): I/flutter (21949): I/flutter (21949): ELEMENT false I/flutter (21949): No elements I/flutter (21949): DONE PARSING FATURES I/flutter (21949): State: XmppConnectionState.DoneParsingFeatures I/flutter (21949): CB-SDK: CubeChatConnection: Chat connection DoneParsingFeatures I/flutter (21949): response: I/flutter (21949): sending: I/flutter (21949): response: I/flutter (21949): I/flutter (21949): I/flutter (21949): sending: I/flutter (21949): CB-SDK: CubeChatConnection: Chat connection Ready I/flutter (21949): CB-SDK: : ========================================================= I/flutter (21949): === REQUEST ==== 256601c5-c5af-4772-8c6a-054d5ae2e3b8 === I/flutter (21949): REQUEST I/flutter (21949): GET https://api.connectycube.com/chat/Dialog I/flutter (21949): HEADERS I/flutter (21949): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 0.4.0, CB-Token: 315b34b90e8b290ac653bc276a3741406e0001dc} I/flutter (21949): BODY I/flutter (21949): I/flutter (21949): I/flutter (21949): response: I/flutter (21949): sending: I/flutter (21949): response: I/flutter (21949): RosterListChanged: [] I/flutter (21949): response: I/flutter (21949): sending: I/flutter (21949): response: I/flutter (21949): No id found for stanza I/flutter (21949): response: I/flutter (21949): sending: I/flutter (21949): response: I/flutter (21949): you too I/flutter (21949): 159947059615f55fbd0ca8bf4404898aba45f55fbf920e3312b074de0a9Offline Storage - localhost I/flutter (21949): CB-SDK: : Receive PRIVATE chat message I/flutter (21949): CB-SDK: : onReceiveMessage global message= {_id: 5f55fbf920e3312b074de0a9, chat_dialog_id: 5f55fbd0ca8bf4404898aba4, message: you too, date_sent: 1599470596, sender_id: 1890495, recipient_id: 1890491, read_ids: null, delivered_ids: null, views_count: null, attachments: [], id: null, created_at: null, updated_at: null, save_to_history: 1, dialog_id: 5f55fbd0ca8bf4404898aba4, message_id: 5f55fbf920e3312b074de0a9} I/flutter (21949): response: I/flutter (21949): sending: I/flutter (21949): CB-SDK: : ********************************************************* I/flutter (21949): *** RESPONSE *** 200 *** 256601c5-c5af-4772-8c6a-054d5ae2e3b8 *** I/flutter (21949): HEADERS I/flutter (21949): {connection: keep-alive, cache-control: max-age=0, private, must-revalidate, set-cookie: _mkra_ctxt=fd6197f1ceb340e899eef57cf0147cd6--200; path=/; max-age=5; HttpOnly; secure, status: 200 OK, transfer-encoding: chunked, date: Mon, 07 Sep 2020 09:56:24 GMT, access-control-allow-origin: *, strict-transport-security: max-age=31536000,max-age=15768000;, content-type: application/json; charset=utf-8, x-xss-protection: 1; mode=block, server: nginx/1.16.1, x-request-id: 70ea5ef4-eec8-4e00-bf92-c93c6f732f77, cb-token-expirationdate: 2020-09-07 11:56:21 UTC, connectycube-rest-api-version: 0.1.1, x-runtime: 0.019975, etag: W/"27b609c25c4792a15ba28d14d13ec279", x-frame-options: SAMEORIGIN, x-content-type-options: nosniff} I/flutter (21949): BODY I/flutter (21949): {"total_entries":1,"skip":0,"limit":100,"items":[{"_id":"5f55fbd0ca8bf4404898aba4","admins_ids":[],"created_at":"2020-09-07T09:22:24Z","description":null,"last_message":"you too","last_message_date_sent":1599470596,"last_message_id":"5f55fbf920e3312b074de0a9","last_message_user_id":1890495,"name":"usr3","occupants_ids":[1890491,1890495],"photo":null,"pinned_messages_ids":[],"type":3,"updated_at":"2020-09-07T09:23:16Z","user_id":1890491,"unread_messages_count":0,"xmpp_room_jid":null}]} I/flutter (21949): I/flutter (21949): CB-SDK: _BodyLayoutState: getDialogs: {currentPage: null, totalEntries: 1, perPage: null, skip: 0, limit: 100, items: [{_id: 5f55fbd0ca8bf4404898aba4, last_message: you too, last_message_date_sent: 1599470596, last_message_user_id: 1890495, photo: null, user_id: 1890491, xmpp_room_jid: null, unread_messages_count: 0, name: usr3, type: 3, description: null, occupants_count: null, occupants_ids: [1890491, 1890495], pinned_messages_ids: [], admins_ids: [], data: null, id: null, created_at: 2020-09-07 09:22:24.000Z, updated_at: 2020-09-07 09:23:16.000Z}]} I/flutter (21949): _logout usr1 and usr1 I/flutter (21949): sending: I/flutter (21949): response: I/flutter (21949): Delivered: CGNJMXVVP I/flutter (21949): Delivered: BPVYYDWCE I/flutter (21949): Delivered: RAAPKCMCE I/flutter (21949): Delivered: TEPVHLJXH I/flutter (21949): Delivered stanza without id presence I/flutter (21949): CB-SDK: : ========================================================= I/flutter (21949): === REQUEST ==== 4cff83d6-600f-4a6e-83bf-4b8540dc0343 === I/flutter (21949): REQUEST I/flutter (21949): DELETE https://api.connectycube.com/login I/flutter (21949): HEADERS I/flutter (21949): {Content-type: application/json, ConnectyCube-REST-API-Version: 0.1.1, CB-SDK: Flutter 0.4.0, CB-Token: 315b34b90e8b290ac653bc276a3741406e0001dc} I/flutter (21949): BODY I/flutter (21949): I/flutter (21949): I/flutter (21949): CB-SDK: : ********************************************************* I/flutter (21949): *** RESPONSE *** 200 *** 4cff83d6-600f-4a6e-83bf-4b8540dc0343 *** I/flutter (21949): HEADERS I/flutter (21949): {connection: keep-alive, cache-control: no-cache, set-cookie: _mkra_ctxt=57d9b7267408d81ae9fffdedcd0fb711--200; path=/; max-age=5; HttpOnly; secure, status: 200 OK, transfer-encoding: chunked, date: Mon, 07 Sep 2020 09:56:30 GMT, access-control-allow-origin: *, strict-transport-security: max-age=31536000,max-age=15768000;, content-type: application/json, x-xss-protection: 1; mode=block, server: nginx/1.16.1, x-request-id: 25a0a080-a3e7-45b5-b957-f85c22b4a67a, cb-token-expirationdate: 2020-09-07 11:56:21 UTC, connectycube-rest-api-version: 0.1.1, x-runtime: 0.018914, x-frame-options: SAMEORIGIN, x-content-type-options: nosniff} I/flutter (21949): BODY I/flutter (21949): I/flutter (21949): I/flutter (21949): State: XmppConnectionState.Closed I/flutter (21949): response: I/flutter (21949): !!!!!!!!!!!Handle secured connection done ```
TatankaConCube commented 4 years ago

hello @DDavidPrime, can you, please, describe how we can reproduce your issue. Please add logs from the flutter console with error for a better understanding of your issue.

gianlucainnocente commented 4 years ago

Same error here. We need to close session and then log in with another user, but calling CubeChatConnection.instance.destroy() it crashes:

The method 'closeStreams' was called on null. Receiver: null Tried calling: closeStreams()

DDavidPrime commented 4 years ago

@TatankaConCube Updated the original issue and added logs (even though I don't think they will be much of help). If anything else I can help with, please let me know.

TatankaConCube commented 4 years ago

we are investigating this issue, thank you for your help

TatankaConCube commented 4 years ago

@DDavidPrime today we released version 0.4.1 with required fixes. Please check and close this ticket if your issue resolved.

DDavidPrime commented 4 years ago

The issue is fixed. Closing this now...