GAE - Telegram bot stops serving after some peroid of time

Telegram bot stops working after some period of time.

I uploaded a simple telegram bot to google-aplication-engine. And after uploading it works as expected some time. Then it stoped respond to request from telegram. The bot is very simple, it uses github.com/go-telegram-bot-api/telegram-bot-api package.

func main() {
    bot, err := tba.NewBotAPI("apitockenhere")
    var ucfg tba.UpdateConfig = tba.NewUpdate(0)
    ucfg.Timeout = 60

    uchan, err := bot.GetUpdatesChan(ucfg)
    if err != nil {
	log.Println(err)
    }
    ...
    for {
        select {
        case update := <-uchan:
        ...
        }
    }
}

If I open web application in browser (it doesnot contais any handlers so it opens nothing) then telegram bot again starts working some time and then stops.

It works as expected localy but there is probably some issues with GAE.
How to modify the code to prevent it from stopping?

I noticed that if I close browser then after some period of time telegram bot also stops working.

It sounds like you bumped into GAE’s scheduling control, where if the app is unattended (idle) for more than 30 seconds, that app will be shut-down automatically and enters wake-up request mode.

You have a choice:

  1. Set a minimum idle instance (under manual scaling which cost $$$)
  2. Use application like Kaffine for Heroku or cron job machine to periodically ping the bot server for avoiding shutdown mode.
  3. Use GCE VM instead of GAE.

You can bring this matter to your Google Cloud tech assistant in your Google Cloud Console for advice.

Doc:
https://cloud.google.com/appengine/docs/standard/go112/how-instances-are-managed


As far as your Go program, it’s working fine.

1 Like

Maybe, The requests cannot past the firewall.

Doubt it was the firewall. OP specifically mentioned that the bot is working fine when the bot is visited via browser, and after uploaded.

I do expect some kind of mechanism for GAE to prevent botting, same as Heroku.

1 Like

exactly

Well, if you got your answer, feel free to “mark as solved”. I will go for option 3 which is a lot easier to setup a small bot.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.