Comments (10)
Are u sure to it resolve a problem the best way? I know clojure a little bit, but I also know that @Otann said you need to catches exceptions in the handler (#17)
My solution:
(defonce telegram-poller (atom nil))
(defn -main
[& args]
(defn start
[]
(go
(try
(reset! telegram-poller (p/start token bot-api))
(catch Exception e
(println (.getMessage e))
(start)))))
(start)
(Thread/sleep Long/MAX_VALUE))
It works well, but it's definitely not a best practice too :)
from morse.
@chiliec I haven't been able to track down what causes the polling to stop, looking through my logs I don't see any exceptions that might cause this (although I might have missed it.)
I think @Otann's advice in #17 is good but from reading the code it looks like it's possible for create-producer
to close the updates
channel (async/thread
will return nil
if its body throws an exception, for example) and thus stop polling, without informing the caller of start
. Exceptions raised in an async/thread
body are not catchable with try/catch
outside of the thread body.
from morse.
@jonathanj hello Jonathan! thank you for the request.
-
would be especially interesting to see why polling has stopped. I think after #17 I've wrapped handling messages with a
catch-all
expression. -
I supposed
go-loop
does return you a channel that is closed after loop is finished, doesn't it?
from morse.
Ah! I see your point now, are you asking for something like this?
(defn start
"Starts long-polling process.
Handler is supposed to process immediately, as it will
be called in a blocking manner."
([token handler] (start token handler {}))
([token handler opts]
(let [running (chan)
updates (create-producer running token opts)
consumer (create-consumer updates handler)]
[running consumer])))
As this should not happen at all, I feel hesitant doing it. @chiliec is right, restarting things when they break is not the best practice ;) I would very much like to fix the root cause and add another try-catch
in the proper place.
Could you try the piece of code above and share your logs/ideas on what causes the stop?
from morse.
What's wrong with restarting things when they break? If the Telegram transport fails (because I have no Internet for 12 hours, for example) either Morse needs to implement retrying (which is at the wrong level, in my opinion, because how and when to retry should be my decision) or my application needs to implement retrying, which it can't do because there is no way for it to know whether the Morse polling loop is alive or not.
It would be nice to know what the root cause is, definitely, unfortunately I haven't managed to figure that out yet. The issue doesn't happen that often for me, so the debugging iteration loop is quite long.
from morse.
@jonathanj nothing is wrong with restarting, what is wrong is when things break. Things should not break ;)
I'm thinking on a proper solution, which will give you that.
In the meantime, what do you thing about the code above?
from morse.
Recently got a similar issue (stopped long polling) and saw this exception:
Exception in thread "async-thread-macro-52" java.lang.Error: java.net.ConnectException: Connection timed out (Connection ti
med out)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1155)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection timed out (Connection timed out)
...
at clj_http.client$request_STAR_.invokeStatic(client.clj:1181)
at clj_http.client$request_STAR_.invoke(client.clj:1174)
at clj_http.client$get.invokeStatic(client.clj:1187)
at clj_http.client$get.doInvoke(client.clj:1183)
at clojure.lang.RestFn.invoke(RestFn.java:423)
at morse.api$get_updates.invokeStatic(api.clj:18)
at morse.api$get_updates.invoke(api.clj:11)
at morse.polling$create_producer$fn__12285$state_machine__7754__auto____12296$fn__12302$inst_12204__12306.invoke(po
lling.clj:26)
at clojure.core.async$thread_call$fn__7963.invoke(async.clj:442)
at clojure.lang.AFn.run(AFn.java:22)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
I found that the updates channel gets closed in case of the exceptions like this:
(go-loop [offset 0]
(let [resopnse (a/thread (api/get-updates token (merge opts {:offset offset})))
[data _] (a/alts! [running resopnse])]
(case data
nil
(close! updates) ; <--
To me it seems quite clean to wrap get-updates into try-catch since it's interacting with real world and shouldn't break the application logic in case of any exception.
from morse.
Dec 21, 2017 5:28:41 PM org.apache.http.impl.client.DefaultHttpClient tryExecute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.telegram.org:443: Operation timed out
This particular thing just happened to me now, I'm sure it's not the only thing causing this but in this case morse isn't restarting properly but I also can't do anything about it from an application perspective, like a bit later retry or use a fallback delivery mechanism or inform someone.
from morse.
@jonathanj @dixel @chiliec
Hey guys, I think I found a way to notify you when polling failed.
I agree that library should not handle reconnects because if there is a misconfiguration, these endless reconnects could piss off the telegram.
I added a small piece that closes running
channel.
It means that you can block on reading from it and then when it happens, reconnect.
Released this as 0.3.1
will this fix this problem for you?
from morse.
@Otann This sounds ideal, I'll upgrade my dependencies. I'm going to close the ticket since the code looks like it solves the issue. Thank you!
from morse.
Related Issues (20)
- Support /command@YourBot style commands HOT 3
- Exception causes long polling process shutdown HOT 2
- Don't leak dev-time dependencies HOT 3
- Not reconnected after 502 error HOT 4
- Is it possible to pass a core.async channel to the "start" function in polling to get the updates directly into it? HOT 7
- Global timeout outside of clj-http for getting updates in the polling process. HOT 1
- Bot freezes for unknown reasons HOT 12
- Got HTTP request timed out HOT 2
- pooling started, but not working HOT 3
- Update handler HOT 1
- no delete-webhook function.
- Long-polling HTTP request timed out, stopping polling HOT 8
- Infinite loop with web hook HOT 1
- Handle upgrading a group to supergroup HOT 3
- Longpolling: Does not survive random 502 from Telegram HOT 3
- inline query did not check if update is a inline query
- 403 Forbidden: bot was blocked by the user HOT 4
- hellonico/morse 0.2.4 ? HOT 1
- Message is sent but throws an exception HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from morse.