rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.77k stars 1.22k forks source link

DefaultBotSession failing intermittantly #957

Closed naude-r closed 3 years ago

naude-r commented 3 years ago

hi,

have noticed that sometimes DefaultBotSession would fail Telegram Connection] ERROR o.t.t.u.DefaultBotSession - Connection pool shut down java.lang.IllegalStateException: Connection pool shut down at org.apache.http.util.Asserts.check(Asserts.java:34) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:269) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:176) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.getUpdatesFromServer(DefaultBotSession.java:250) at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:189)

this leads to the reader thread being shutdown

there is no callback and seemingly no way to recover from this. the bot can still send messages, but nothing is received from the api.

would it be possible to:

  1. add a callback to allow an implementation to restart the bot?
  2. auto restart the reader thread?

(1) is probably a safer option with limited change require.

naude-r commented 3 years ago

hi,

have noticed that sometimes DefaultBotSession would fail Telegram Connection] ERROR o.t.t.u.DefaultBotSession - Connection pool shut down java.lang.IllegalStateException: Connection pool shut down at org.apache.http.util.Asserts.check(Asserts.java:34) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.requestConnection(PoolingHttpClientConnectionManager.java:269) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:176) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.getUpdatesFromServer(DefaultBotSession.java:250) at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:189)

this leads to the reader thread being shutdown

there is no callback and seemingly no way to recover from this. the bot can still send messages, but nothing is received from the api.

would it be possible to:

1. add a callback to allow an implementation to restart the bot?

2. auto restart the reader thread?

(1) is probably a safer option with limited change require.

a thread dump indicated that the ReaderThread is running after all, just waiting per the back-off. have adjusted the defaults a bit. will have to wait and see if that helped.

naude-r commented 3 years ago

the smaller back-off worked just fine.