Open dark4eg opened 6 years ago
Thanks! I'll look into it soon.
As a temporary workaround, try maybe adding a timeout?
(def channel (p/start token handler {:timeout 10}))
I have the same issue. Adding {:timeout 10}
didn't help
Same thing happened to me, any news on this issue yet?
Same thing happened to me, any news on this issue yet?
Here https://github.com/Otann/morse/blob/bbb2efc6a8eb17603a56121fbe10e1592ce5d8ee/src/morse/polling.clj#L43
I've added (System/exit 1)
right after (close! updates)
, to crash app instead of freeze. This is a bad solution, but I haven't come up with anything better to prevent freezes :(
You can create file polling_patch.clj
:
(ns morse.polling-patch
(:require [morse.polling]))
(in-ns 'morse.polling)
(defn create-producer
"Passed channel should be always empty.
Close it to stop long-polling.
Returns channel with updates from Telegram"
[running token opts]
(let [updates (a/chan)
;; timeout for Telegram API in seconds
timeout (or (:timeout opts) 1)]
(go-loop [offset 0]
(let [;; fix for JDK bug https://bugs.openjdk.java.net/browse/JDK-8075484
;; introduce additional timeout 10 times more that telegram's one
wait-timeout (a/go (a/<! (a/timeout (* 1000 timeout 10)))
::wait-timeout)
response (api/get-updates-async token (assoc opts :offset offset))
[data _] (a/alts! [running response wait-timeout])]
(case data
;; running got closed by the user
nil
(do (log/info "Stopping Telegram polling...")
(close! wait-timeout)
(close! updates))
::wait-timeout
(do (log/error "HTTP request timed out, stopping polling")
(close! running)
(close! updates)
(log/fatal "ABORT")
(System/exit 1))
::api/error
(do (log/warn "Got error from Telegram API, stopping polling")
(close! running)
(close! updates))
(do (close! wait-timeout)
(doseq [upd data] (>! updates upd))
(recur (new-offset data offset))))))
updates))
(in-ns 'morse.polling-patch)
And then require this morse.polling-patch
somewhere in your project
Thanks for the quick reply, I'll try it out!
I've added (System/exit 1) right after (close! updates), to crash app instead of freeze.
Thanks for the workaround. It really "solved" my problem. And I use it also for the ::api/error branch. Anyway, does anybody have an explanation why these problem arise in the first place?
FWIW on ::api/error
I get:
SocketException The transport's socket appears to have lost its connection to the nREPL server
nrepl.transport/bencode/fn--9182/fn--9183 (transport.clj:108)
nrepl.transport/bencode/fn--9182 (transport.clj:108)
nrepl.transport/fn-transport/fn--9150 (transport.clj:55)
clojure.core/binding-conveyor-fn/fn--5739 (core.clj:2030)
java.util.concurrent.FutureTask.run (FutureTask.java:264)
java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
java.lang.Thread.run (Thread.java:834)
Bye for now!
Maybe it will be useful for somebody. 0.3.1 - the last version that works with long-polling without this issue. 0.3.2 was rewritten to use async that fails with time-out unfrotufately.
Long-polling
sample code from README.md
returned
ERROR morse.polling - HTTP request timed out, stopping polling