elbekD / kt-telegram-bot

Telegram Bot Library for Kotlin language
MIT License
103 stars 19 forks source link

Bot.stop leaves active HTTP task running #47

Closed filipceko closed 2 years ago

filipceko commented 2 years ago

Hi guys, thanks for the great API. I have been playing with the Telegram bot for some time now.

Recently I stumbled upon an issue. Seems like after I build and launch my bot, the stop() call wouldn't clean up all of its background tasks and my app kept running until killed.

It's possible I made some wrong call or forgot to close something but the running thread points towards the bots' network communication.

override suspend fun launch() {
  telegramBot = Bot.createPolling(
      username = Application.config.getProperty("telegram.username"),
      token = Application.config.getProperty("telegram.token")
  )
  services.forEach { service ->
      telegramBot.onCommand("/${service.command}") { onCommand(it.first, service) }
  }
  telegramBot.setMyCommands(services.filter { it.isUIService }.map { BotCommand(it.command, it.getHint()) })
  telegramBot.onMessage(this::onMessage)
  telegramBot.onEditedMessage(this::onMessage)
  telegramBot.onCallbackQuery(this::onCallBackQuery)
  telegramBot.start()
  fetchMe()
}

override fun stop() {
  services.forEach {
      it.onStop()
  }
  telegramBot.stop()
  getLogger().info { "$name stopped" }
}

None of my services create any network communication.

With regards, Filip.

filipceko commented 2 years ago

Ok, I am sorry about bothering you, I found my mistake - totally unrelated to this project.