Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long-polling HTTP request timed out, stopping polling #40

Open
dark4eg opened this issue Jun 6, 2018 · 8 comments
Open

Long-polling HTTP request timed out, stopping polling #40

dark4eg opened this issue Jun 6, 2018 · 8 comments

Comments

@dark4eg
Copy link

dark4eg commented Jun 6, 2018

Long-polling

sample code from README.md

(require '[morse.polling :as p])
(def channel (p/start token handler))

returned

ERROR morse.polling - HTTP request timed out, stopping polling

@Otann
Copy link
Owner

Otann commented Jun 7, 2018

Thanks! I'll look into it soon.

As a temporary workaround, try maybe adding a timeout?

(def channel (p/start token handler {:timeout 10}))

@KGOH
Copy link

KGOH commented Apr 29, 2019

I have the same issue. Adding {:timeout 10} didn't help

@jakuzure
Copy link

Same thing happened to me, any news on this issue yet?

@KGOH
Copy link

KGOH commented Jun 18, 2019

Same thing happened to me, any news on this issue yet?

Here

(close! updates))

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

@jakuzure
Copy link

Thanks for the quick reply, I'll try it out!

@Bost
Copy link

Bost commented Feb 4, 2020

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?

@Bost
Copy link

Bost commented Feb 4, 2020

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!

@marksto marksto self-assigned this Jul 2, 2021
@marksto marksto removed their assignment Jul 4, 2021
@dmisiuk
Copy link

dmisiuk commented Feb 13, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants