node-telegram-bot-api: getUpdates ETELEGRAM 409 Conflict: terminated by other getUpdates request;

 {"code":"ETELEGRAM","message":"ETELEGRAM: 409 Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}

I’m getting this error some times on restart bot. Does somebody know more information or how to check running instances?
I see more people catch the same error, but nobody can response. #488

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 28
  • Comments: 35 (1 by maintainers)

Most upvoted comments

i after millions of hits. I decided to php the bot

but how to run 2 instances of the bot on one server?

I solved it by manually starting and ending my pooling once my function starts and ends (and removed: { polling: true } option from the bot object instantiation). I also did a check to stop the polling if by any reason its active before we’re trying to start a new poll. eg.

if(bot.isPolling()) { await bot.stopPolling(); }

await bot.startPolling();

[SOME CODE]

await bot.stopPolling();

This can be caused by manual startPolling() calling, due to polling start automatically if you passed {polling: true} when creating a bot

@askucher Only one istance can listen for updates, otherwise you must use two different bot token

That error means: “There are two or more bots that listen updates at same bot token” So i think you can check process list in your server, what system you use to keep bot alway on? (for example i use pm2)

To print all exception use:

process.on('uncaughtException', function (error) {
	console.log("\x1b[31m", "Exception: ", error, "\x1b[0m");
});

process.on('unhandledRejection', function (error, p) {
	console.log("\x1b[31m","Error: ", error.message, "\x1b[0m");
});

But ETELEGRAM means an error printed by telegram server, you can’t get other infos.

@sidelux as Telegram only allow on instance can listen for updates, then how can we scale that instance service what happen if that process handle large messages requests

Finally, I found the cause of this problem in my situation. I created the telegram bot service and initialized it there. I used it in my Telegram bot service constructor and in the application service (injected it). Because of this, it was initialized twice when the application was launched. It was my mistake. I also tried telegraf.js and grammy.js, there also appeared this conflict error message. You should initialize TelegramBot once and in another file from service file. I hope it will be useful.

I also have this error when I use a Telegram bot extending from LongPollingTelegram. 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 : `<dependency> <groupId>org.telegram</groupId> <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 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 : “409 Conflict: completed by another getUpdates request;”. And this error repeats every second. What am I doing wrong? I can’t figure it out. The support of Telegram is not answer for my email.

I understand it’s quite a late reply to this thread, in my case (and I think for most others) the issue is, pm2 tries to start loadbalancer with instances: 'max' , and when more than 1 (pm2) instance is possible then, for polling on both the instances telegrams complains this error which is logical.

Had the same problem. The first bot listener was running in the background. Solved it with task manager (Ctr + Shift + Esc) -> “Python” process -> right click -> remove the task

I guess telegram engineers didn’t want to make complex API with message balancing or synchronization tokens, or whatever.

If you want to run several node.js instances in one node.js cluster, I’d recommend polling events in master process and sending them to workers in process.send() If you want to run your bot on several servers, I would recommend creating a lightweight balancing proxy (possibly, with a failover instance waiting nearby) that sends updates to workers. You could do balancing on your own, or use some job queue, like RabbitMQ. The idea stays the same, basically =)