|
756 | 756 |
|
757 | 757 | (send-handshake! server-ch websocket?)
|
758 | 758 |
|
759 |
| - ;; Start ws-kalive loop |
760 |
| - ;; This also works to gc ws conns that were suddenly |
761 |
| - ;; terminated (e.g. by turning on airplane mode) |
| 759 | + ;; Start server-side ws-kalive loop |
| 760 | + ;; Also helps server detect broken conns earlier |
762 | 761 | (when-let [ms ws-kalive-ms]
|
763 | 762 | (go-loop [udt-t0 udt-open]
|
764 | 763 | (<! (async/timeout ms))
|
765 |
| - (when-let [[_sch udt-t1] (get-in @conns_ [:ws uid client-id])] |
766 |
| - (when (interfaces/sch-open? server-ch) |
767 |
| - ;; (assert (= _sch server-ch)) |
| 764 | + (when-let [[sch udt-t1] (get-in @conns_ [:ws uid client-id])] |
| 765 | + (when (identical? sch server-ch) |
768 | 766 | (when (= udt-t1 udt-t0)
|
769 |
| - ;; Ref. issue #230: |
770 |
| - ;; We've seen no send/recv activity on this |
771 |
| - ;; conn w/in our kalive window so send a ping |
772 |
| - ;; ->client (should auto-close conn if it's |
773 |
| - ;; gone dead). |
774 |
| - (interfaces/sch-send! server-ch websocket? |
775 |
| - (pack packer :chsk/ws-ping))) |
776 |
| - (recur udt-t1)))))) |
| 767 | + ;; Ref. #230 |
| 768 | + ;; No conn send/recv activity w/in kalive window |
| 769 | + ;; so send ping to client. Should trigger close |
| 770 | + ;; if conn is broken. |
| 771 | + (interfaces/sch-send! server-ch websocket? |
| 772 | + (pack packer :chsk/ws-ping))) |
| 773 | + (recur udt-t1)))))) |
777 | 774 |
|
778 | 775 | ;; Ajax handshake/poll
|
779 | 776 | (let [_ (tracef "New Ajax handshake/poll: %s (%s)" uid sch-uuid)
|
|
791 | 788 | (when-let [ms lp-timeout-ms]
|
792 | 789 | (go
|
793 | 790 | (<! (async/timeout ms))
|
794 |
| - (when-let [[_sch udt-t1] (get-in @conns_ [:ajax uid client-id])] |
795 |
| - (when (= udt-t1 udt-open) |
796 |
| - ;; (assert (= _sch server-ch)) |
797 |
| - ;; Appears to still be the active sch |
| 791 | + (when-let [[sch udt-t1] (get-in @conns_ [:ajax uid client-id])] |
| 792 | + (when (and (= identical? server-ch) (= udt-t1 udt-open)) |
798 | 793 | (interfaces/sch-send! server-ch websocket?
|
799 | 794 | (pack packer :chsk/timeout))))))))))
|
800 | 795 |
|
|
828 | 823 | (<! (async/timeout 5000)) ; TODO Configurable
|
829 | 824 | (let [disconnect? ; Removed entry for client-id?
|
830 | 825 | (swap-in! conns_ [conn-type uid client-id]
|
831 |
| - (fn [[_sch udt-t1]] |
832 |
| - (if (= udt-t1 udt-close) |
| 826 | + (fn [[sch udt-t1]] |
| 827 | + (if (and (identical? sch server-ch) (= udt-t1 udt-close)) |
833 | 828 | (swapped :swap/dissoc true)
|
834 | 829 | (swapped :swap/abort false))))]
|
835 | 830 |
|
|
1358 | 1353 | (reset! retry-count_ 0)
|
1359 | 1354 | (connect-fn)
|
1360 | 1355 |
|
| 1356 | + ;; Start client-side ws-kalive loop |
| 1357 | + ;; Also helps client detect broken conns earlier |
1361 | 1358 | (when-let [ms ws-kalive-ms]
|
1362 | 1359 | (go-loop []
|
1363 | 1360 | (let [udt-t0 @udt-last-comms_]
|
1364 | 1361 | (<! (async/timeout ms))
|
1365 | 1362 | (when (have-handle?)
|
1366 | 1363 | (let [udt-t1 @udt-last-comms_]
|
1367 | 1364 | (when (= udt-t0 udt-t1)
|
1368 |
| - ;; Ref. issue #259: |
1369 |
| - ;; We've seen no send/recv activity on this |
1370 |
| - ;; conn w/in our kalive window so send a ping |
1371 |
| - ;; ->server (should auto-close conn if it's |
1372 |
| - ;; gone dead). The server generally sends pings so |
1373 |
| - ;; this should be rare. Mostly here to help clients |
1374 |
| - ;; identify conns that were suddenly dropped. |
1375 |
| - |
| 1365 | + ;; Ref. #259 |
| 1366 | + ;; No conn send/recv activity w/in kalive window |
| 1367 | + ;; so send ping to server. Should trigger close |
| 1368 | + ;; if conn is broken. |
1376 | 1369 | (-chsk-send! chsk [:chsk/ws-ping] {:flush? true})))
|
1377 | 1370 | (recur)))))
|
1378 | 1371 |
|
|
0 commit comments