Coder Social home page Coder Social logo

Comments (8)

KGOH avatar KGOH commented on May 27, 2024 2

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

from morse.

jakuzure avatar jakuzure commented on May 27, 2024 1

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

from morse.

Otann avatar Otann commented on May 27, 2024

Thanks! I'll look into it soon.

As a temporary workaround, try maybe adding a timeout?

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

from morse.

KGOH avatar KGOH commented on May 27, 2024

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

from morse.

jakuzure avatar jakuzure commented on May 27, 2024

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

from morse.

Bost avatar Bost commented on May 27, 2024

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?

from morse.

Bost avatar Bost commented on May 27, 2024

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!

from morse.

dmisiuk avatar dmisiuk commented on May 27, 2024

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.

from morse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.