aiogram: Polling doesn't stop on receiving SIGTERM in Docker

I have been using docker for a while and I have noticed 10 second delay before stopping the container. Now I realized that it is because aiogram doesn’t shutdown when SIGTERM signal was sent. When do docker kill --signal SIGINT, everything looks normal now.

Is it possible to make aiogram to shutdown on SIGTERM as well?

About this issue

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

Commits related to this issue

Most upvoted comments

@kamikazebr yes, I have already deleted the bot after 2days

Solved the problem by setting handlers myself

 bot = Bot(token=bot_token)
 storage = RedisStorage2(host=redis_host)
 dp = Dispatcher(bot, storage=storage)

 asyncio.get_event_loop().add_signal_handler(signal.SIGTERM, dp.stop_polling)
 asyncio.get_event_loop().add_signal_handler(signal.SIGINT, dp.stop_polling)

 await dp.start_polling()

 await storage.close()
 await bot.close()
 await dp.wait_closed()
 await storage.wait_closed()

Btw this issue happens only in docker 🤔

https://asciinema.org/a/tLyPYlfnexaL9bFrI7HPw0wjh