Răsfoiți Sursa

fix(rtc): catch ex-break-rtc-loop in rtc-loop

rcmerci 1 an în urmă
părinte
comite
4db9acd5ec
2 a modificat fișierele cu 37 adăugiri și 36 ștergeri
  1. 1 1
      src/main/frontend/db_worker.cljs
  2. 36 35
      src/main/frontend/worker/rtc/core.cljs

+ 1 - 1
src/main/frontend/db_worker.cljs

@@ -3,7 +3,7 @@
   (:require ["@logseq/sqlite-wasm" :default sqlite3InitModule]
             ["comlink" :as Comlink]
             [cljs-bean.core :as bean]
-            [clojure.core.async :as async]
+            [cljs.core.async :as async]
             [clojure.edn :as edn]
             [clojure.string :as string]
             [cognitect.transit :as transit]

+ 36 - 35
src/main/frontend/worker/rtc/core.cljs

@@ -970,46 +970,47 @@
           (when (:ex-data resp) (handle-remote-genernal-exception resp state))
           (async/sub data-from-ws-pub "push-updates" push-data-from-ws-ch)
           (when loop-started-ch (async/close! loop-started-ch))
-          (<! (go-loop [push-client-ops-ch
-                        (make-push-client-ops-timeout-ch repo (not @*auto-push-client-ops?))]
-                (let [{:keys [push-data-from-ws client-op-update stop continue]}
-                      (async/alt!
-                        toggle-auto-push-client-ops-ch {:continue true}
-                        force-push-client-ops-ch {:client-op-update true}
-                        push-client-ops-ch ([v] (if (and @*auto-push-client-ops? (true? v))
-                                                  {:client-op-update true}
-                                                  {:continue true}))
-                        push-data-from-ws-ch ([v] {:push-data-from-ws v})
-                        stop-rtc-loop-chan {:stop true}
-                        :priority true)]
-                  (cond
-                    continue
-                    (recur (make-push-client-ops-timeout-ch repo (not @*auto-push-client-ops?)))
-
-                    push-data-from-ws
-                    (let [r (<! (<push-data-from-ws-handler state repo conn date-formatter push-data-from-ws))]
-                      (when (= r ::need-pull-remote-data)
-                        ;; trigger a force push, which can pull remote-diff-data from local-t to remote-t
-                        (async/put! force-push-client-ops-ch true))
-                      (recur (make-push-client-ops-timeout-ch repo (not @*auto-push-client-ops?))))
-
-                    client-op-update
-                    ;; FIXME: access token expired
-                    (let [_ (<! (<client-op-update-handler state token))]
-                      (recur (make-push-client-ops-timeout-ch repo (not @*auto-push-client-ops?))))
-
-                    stop
-                    (stop-rtc-helper state)
-
-                    :else
-                    nil))))
+          (<?
+           (go-try
+             (loop [push-client-ops-ch
+                    (make-push-client-ops-timeout-ch repo (not @*auto-push-client-ops?))]
+               (let [{:keys [push-data-from-ws client-op-update stop continue]}
+                     (async/alt!
+                       toggle-auto-push-client-ops-ch {:continue true}
+                       force-push-client-ops-ch {:client-op-update true}
+                       push-client-ops-ch ([v] (if (and @*auto-push-client-ops? (true? v))
+                                                 {:client-op-update true}
+                                                 {:continue true}))
+                       push-data-from-ws-ch ([v] {:push-data-from-ws v})
+                       stop-rtc-loop-chan {:stop true}
+                       :priority true)]
+                 (cond
+                   continue
+                   (recur (make-push-client-ops-timeout-ch repo (not @*auto-push-client-ops?)))
+
+                   push-data-from-ws
+                   (let [r (<! (<push-data-from-ws-handler state repo conn date-formatter push-data-from-ws))]
+                     (when (= r ::need-pull-remote-data)
+                       ;; trigger a force push, which can pull remote-diff-data from local-t to remote-t
+                       (async/put! force-push-client-ops-ch true))
+                     (recur (make-push-client-ops-timeout-ch repo (not @*auto-push-client-ops?))))
+
+                   client-op-update
+                   ;; FIXME: access token expired
+                   (let [_ (<? (<client-op-update-handler state token))]
+                     (recur (make-push-client-ops-timeout-ch repo (not @*auto-push-client-ops?))))
+
+                   stop
+                   (stop-rtc-helper state)
+
+                   :else
+                   nil)))))
           (async/unsub data-from-ws-pub "push-updates" push-data-from-ws-ch)
           (catch :default e
             (case (:type (ex-data e))
               ::break-rtc-loop (prn :break-rtc-loop)
               ;; else
-              (prn ::unknown-ex e)
-              )))))))
+              (prn ::unknown-ex e))))))))
 
 
 ;;;  APIs ================================================================