From dd2ff1121623d07ffb2fc074d1eb102725feef7e Mon Sep 17 00:00:00 2001 From: Roman Volosovskyi Date: Wed, 19 Dec 2018 14:20:03 +0200 Subject: [PATCH] [#7139] Fix crash on logout The crash was caused by RPC calls which happened after `StopNode` call. Implementation: - The first suggestion was to `StopNode` only after all `.stopWatching` calls are done, but this only lowered probability of the crash, but did not fix the issue. - Another suggestion was to prevent RPC calls after `StopNode` call, but it also only lowered probability of the crash. - So the last resort was a fix on `status-go` side https://github.com/status-im/status-go/pull/1329, and it actually worked. - Advanced settings are hidden until `Statusgo.Login` is finished --- STATUS_GO_VERSION | 2 +- src/status_im/accounts/logout/core.cljs | 14 ++++++++++---- src/status_im/events.cljs | 8 ++++++-- src/status_im/native_module/core.cljs | 10 ++++++++-- src/status_im/transport/core.cljs | 4 ++-- src/status_im/transport/filters.cljs | 15 ++++++++++----- src/status_im/ui/screens/profile/user/views.cljs | 3 ++- 7 files changed, 39 insertions(+), 17 deletions(-) diff --git a/STATUS_GO_VERSION b/STATUS_GO_VERSION index 361c4fff14..3ecb42649f 100644 --- a/STATUS_GO_VERSION +++ b/STATUS_GO_VERSION @@ -1 +1 @@ -0.17.9-beta +0.17.10-beta.1 diff --git a/src/status_im/accounts/logout/core.cljs b/src/status_im/accounts/logout/core.cljs index 4b385d96e1..0a99a12f21 100644 --- a/src/status_im/accounts/logout/core.cljs +++ b/src/status_im/accounts/logout/core.cljs @@ -13,10 +13,16 @@ {:keychain/clear-user-password (get-in db [:account/account :address]) :dev-server/stop nil} (transactions/stop-sync) - (transport/stop-whisper) - (init/initialize-app-db) - (init/load-accounts-and-initialize-views) - (node/stop))) + (transport/stop-whisper + #(re-frame/dispatch [:accounts.logout/filters-removed])))) + +(fx/defn leave-account + [cofx] + (fx/merge + cofx + (init/initialize-app-db) + (init/load-accounts-and-initialize-views) + (node/stop))) (fx/defn show-logout-confirmation [_] {:ui/show-confirmation diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index 169a1158ff..17c2be5f26 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -286,15 +286,19 @@ (handlers/register-handler-fx :accounts.logout.ui/logout-confirmed - [(re-frame/inject-cofx :data-store/get-all-accounts)] (fn [cofx _] (accounts.logout/logout cofx))) +(handlers/register-handler-fx + :accounts.logout/filters-removed + [(re-frame/inject-cofx :data-store/get-all-accounts)] + (fn [cofx] + (accounts.logout/leave-account cofx))) + ;; accounts update module (handlers/register-handler-fx :accounts.update.callback/save-settings-success - [(re-frame/inject-cofx :data-store/get-all-accounts)] (fn [cofx _] (accounts.logout/logout cofx))) diff --git a/src/status_im/native_module/core.cljs b/src/status_im/native_module/core.cljs index 0d44e51203..180eac5876 100644 --- a/src/status_im/native_module/core.cljs +++ b/src/status_im/native_module/core.cljs @@ -6,10 +6,14 @@ (defn start-node [config] (native-module/start-node config)) +(def node-started (atom false)) + (defn node-ready [] + (reset! node-started true) (native-module/node-ready)) (defn stop-node [] + (reset! node-started false) (native-module/stop-node)) (defn create-account [password callback] @@ -31,10 +35,12 @@ (native-module/clear-web-data)) (defn call-rpc [payload callback] - (native-module/call-rpc payload callback)) + (when @node-started + (native-module/call-rpc payload callback))) (defn call-private-rpc [payload callback] - (native-module/call-private-rpc payload callback)) + (when @node-started + (native-module/call-private-rpc payload callback))) (defn sign-message [rpcParams callback] (native-module/sign-message rpcParams callback)) diff --git a/src/status_im/transport/core.cljs b/src/status_im/transport/core.cljs index 3b655cbe6b..f4f1b4318c 100644 --- a/src/status_im/transport/core.cljs +++ b/src/status_im/transport/core.cljs @@ -68,6 +68,6 @@ It is necessary to remove the filters because status-go there isn't currently a logout feature in status-go to clean-up after logout. When logging out of account A and logging in account B, account B would receive account A messages without this." - [{:keys [db]}] + [{:keys [db]} callback] (let [{:transport/keys [filters]} db] - {:shh/remove-filters filters})) + {:shh/remove-filters [filters callback]})) diff --git a/src/status_im/transport/filters.cljs b/src/status_im/transport/filters.cljs index 91195a3636..9094d35072 100644 --- a/src/status_im/transport/filters.cljs +++ b/src/status_im/transport/filters.cljs @@ -7,12 +7,14 @@ [status-im.utils.handlers :as handlers] [taoensso.timbre :as log])) -(defn remove-filter! [{:keys [chat-id filter]}] +(defn remove-filter! [{:keys [chat-id filter success-callback?] + :or {success-callback? true}}] (.stopWatching filter (fn [error _] (if error (log/warn :remove-filter-error filter error) - (re-frame/dispatch [:shh.callback/filter-removed chat-id])))) + (when success-callback? + (re-frame/dispatch [:shh.callback/filter-removed chat-id]))))) (log/debug :stop-watching filter)) (defn add-filter! @@ -72,7 +74,10 @@ (re-frame/reg-fx :shh/remove-filters - (fn [filters] + (fn [[filters callback]] (doseq [[chat-id filter] filters] - (when filter (remove-filter! {:chat-id chat-id - :filter filter}))))) + (when filter (remove-filter! + {:chat-id chat-id + :filter filter + :success-callback false}))) + (callback))) diff --git a/src/status_im/ui/screens/profile/user/views.cljs b/src/status_im/ui/screens/profile/user/views.cljs index 7cddc4d979..0ef4cfe493 100644 --- a/src/status_im/ui/screens/profile/user/views.cljs +++ b/src/status_im/ui/screens/profile/user/views.cljs @@ -255,4 +255,5 @@ (i18n/label :t/share-my-profile)]] [react/view styles/my-profile-info-container [my-profile-settings current-account shown-account currency (nil? login-data)]] - [advanced shown-account on-show-advanced]]]))) + (when (nil? login-data) + [advanced shown-account on-show-advanced])]])))