mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 08:50:57 -05:00
:sparkles Minor changes on websockets error handling.
This commit is contained in:
parent
36016ad9ef
commit
bf55250ae9
1 changed files with 18 additions and 11 deletions
|
@ -48,8 +48,8 @@
|
||||||
::output-buff-size
|
::output-buff-size
|
||||||
::idle-timeout
|
::idle-timeout
|
||||||
::metrics]
|
::metrics]
|
||||||
:or {input-buff-size 32
|
:or {input-buff-size 64
|
||||||
output-buff-size 32
|
output-buff-size 64
|
||||||
idle-timeout 30000}
|
idle-timeout 30000}
|
||||||
:as options}]
|
:as options}]
|
||||||
(fn [_]
|
(fn [_]
|
||||||
|
@ -67,10 +67,7 @@
|
||||||
created-at (dt/now)
|
created-at (dt/now)
|
||||||
|
|
||||||
on-terminate
|
on-terminate
|
||||||
(fn [& [_ error]]
|
(fn [& args]
|
||||||
(when (ex/exception? error)
|
|
||||||
(l/warn :hint (ex-message error) :cause error))
|
|
||||||
|
|
||||||
(when (compare-and-set! terminated false true)
|
(when (compare-and-set! terminated false true)
|
||||||
(call-mtx metrics :connections {:cmd :dec :by 1})
|
(call-mtx metrics :connections {:cmd :dec :by 1})
|
||||||
(call-mtx metrics :sessions {:val (/ (inst-ms (dt/diff created-at (dt/now))) 1000.0)})
|
(call-mtx metrics :sessions {:val (/ (inst-ms (dt/diff created-at (dt/now))) 1000.0)})
|
||||||
|
@ -80,6 +77,13 @@
|
||||||
(a/close! output-ch)
|
(a/close! output-ch)
|
||||||
(a/close! input-ch)))
|
(a/close! input-ch)))
|
||||||
|
|
||||||
|
on-error
|
||||||
|
(fn [_ error]
|
||||||
|
(on-terminate)
|
||||||
|
(when-not (or (instance? org.eclipse.jetty.websocket.api.exceptions.WebSocketTimeoutException error)
|
||||||
|
(instance? java.nio.channels.ClosedChannelException error))
|
||||||
|
(l/error :hint (ex-message error) :cause error)))
|
||||||
|
|
||||||
on-connect
|
on-connect
|
||||||
(fn [conn]
|
(fn [conn]
|
||||||
(call-mtx metrics :connections {:cmd :inc :by 1})
|
(call-mtx metrics :connections {:cmd :inc :by 1})
|
||||||
|
@ -106,16 +110,19 @@
|
||||||
on-message
|
on-message
|
||||||
(fn [_ message]
|
(fn [_ message]
|
||||||
(call-mtx metrics :messages {:labels ["recv"]})
|
(call-mtx metrics :messages {:labels ["recv"]})
|
||||||
(let [message (t/decode-str message)]
|
(try
|
||||||
(when-not (a/offer! input-ch message)
|
(let [message (t/decode-str message)]
|
||||||
(l/warn :hint "drop messages"))))
|
(a/offer! input-ch message))
|
||||||
|
(catch Throwable e
|
||||||
|
(l/warn :hint "error on decoding incoming message from websocket"
|
||||||
|
:cause e))))
|
||||||
|
|
||||||
on-pong
|
on-pong
|
||||||
(fn [_ buffer]
|
(fn [_ buffer]
|
||||||
(a/>!! pong-ch buffer))]
|
(a/>!! pong-ch buffer))]
|
||||||
|
|
||||||
{:on-connect on-connect
|
{:on-connect on-connect
|
||||||
:on-error on-terminate
|
:on-error on-error
|
||||||
:on-close on-terminate
|
:on-close on-terminate
|
||||||
:on-text on-message
|
:on-text on-message
|
||||||
:on-pong on-pong}))))
|
:on-pong on-pong}))))
|
||||||
|
@ -174,7 +181,7 @@
|
||||||
[{:keys [::conn ::close-ch ::on-close ::pong-ch
|
[{:keys [::conn ::close-ch ::on-close ::pong-ch
|
||||||
::heartbeat-interval ::max-missed-heartbeats]
|
::heartbeat-interval ::max-missed-heartbeats]
|
||||||
:or {heartbeat-interval 2000
|
:or {heartbeat-interval 2000
|
||||||
max-missed-heartbeats 8}}]
|
max-missed-heartbeats 4}}]
|
||||||
(let [beats (atom #{})]
|
(let [beats (atom #{})]
|
||||||
(a/go-loop [i 0]
|
(a/go-loop [i 0]
|
||||||
(let [[_ port] (a/alts! [close-ch (a/timeout heartbeat-interval)])]
|
(let [[_ port] (a/alts! [close-ch (a/timeout heartbeat-interval)])]
|
||||||
|
|
Loading…
Reference in a new issue