rubenlagus / TelegramBots

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

o.t.t.u.DefaultBotSession$ReaderThread : Error getting updates: [409] Conflict: terminated by other getUpdates request; make sure that only one bot instance is running #1221

Closed evgeniy2702 closed 1 year ago

evgeniy2702 commented 1 year ago

Hy everyone. I have this error when I use a Telegram bot extending from LongPollingTelegram. I am sure that i have only one instance of my bot in work. My bot is written in SpringBoot version 2.6.4, java version 1.8.0_271, which is deployed on tomcat version 9.0.56 under linux. I used the following dependencies for the Telegram bot : `

org.telegram
    <artifactId>telegrambots-spring-boot-starter</artifactId>
    <version>5.6.0</version>
</dependency>
<dependency>
    <groupId>org.telegram</groupId>
    <artifactId>telegrambots</artifactId>
    <version>5.6.0</version>
</dependency>`

I use the following code to initialize my bot :

@EventListener({ContextRefreshedEvent.class}) public void init() throws TelegramApiException{ consoleLogger.info("Start initializer MediaBot ."); TelegramBotsApi telegramBotsApi = new TelegramBotsApi(DefaultBotSession.class); try{ BotSession session = telegramBotsApi.registerBot(bot); bot.setSession(session); } catch (TelegramApiException e) { consoleLogger.error("Error occurred: " + e.getMessage()); } }

And my bean of bot has the following PreDestroy method to close and release all resources:

@PreDestroy public void preDestroy(){ consoleLogger.info("Stop bots session ."); this.onClosing(); this.getSession().stop(); consoleLogger.error("Bot session was stopped ."); }

But when I deploy my bot from tomcat, I get the following error :

[gram Connection] o.t.t.u.DefaultBotSession$ReaderThread : Error getting updates: [409] Conflict: terminated by other getUpdates request; make sure that only one bot instance is running org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException: Error getting updates: [409] Conflict: terminated by other getUpdates request; make sure that only one bot instance is running at org.telegram.telegrambots.meta.api.methods.updates.GetUpdates.deserializeResponse(GetUpdates.java:93) ~[telegrambots-meta-5.6.0.jar:?] at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.getUpdatesFromServer(DefaultBotSession.java:260) ~[telegrambots-5.6.0.jar:?] at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:189) [telegrambots-5.6.0.jar:?]

And this error repeats every second. BUT the most interesting thing is that my bot still partially works after undeploying. So, what am I doing wrong? I can't figure it out. The support of Telegram is not answer for my email.

Chase22 commented 1 year ago

The spring boot starter registers any bots found in the injection context by itself, so you have two instances is the bot running if you register it yourself as well

evgeniy2702 commented 1 year ago

The spring boot starter registers any bots found in the injection context by itself, so you have two instances is the bot running if you register it yourself as well

Thank you so much for your feedback. I broked my head trying to figure out what the cause is. And I should have figured out the dependencies.