teloxide: Bot stops responding after some time: Only to commands in group chats it seems

I tried this code:

#[tokio::main]
async fn main() {
    pretty_env_logger::init();
    log::info!("Starting command bot...");

    let bot = Bot::new(CONFIG.telegram_token.as_str());

    Command::repl(bot, answer).await;
}

#[derive(BotCommands, Clone)]
#[command(rename_rule = "lowercase", description = "These commands are supported:")]
enum Command {
    #[command(description = "Responds with info required to setup this bot.")]
    Info,
    #[command(description = "display this text.")]
    Help,
    #[command(description = "update a stack. Parameters: env,stack", parse_with = "split")]
    Update { env: String, stack: String },
}

async fn answer(bot: Bot, msg: Message, cmd: Command) -> ResponseResult<()> {
    match cmd {
        Command::Info =>
            bot.send_message(msg.chat.id,
                             if is_allowed_chat(msg.chat.id) {
                                 format!("Your bot is correctly configured to answer to this chat and execute given updates")
                             } else {
                                 format!("Please configure your bot to allow processing of your chat.\nAdd the chat id to the list of allowed ones in the config.toml.\n\nYour chat id: {}", msg.chat.id)
                             }).await?,
        Command::Help => bot.send_message(msg.chat.id, Command::descriptions().to_string()).await?,
        Command::Update { env, stack } => {
            log::info!("Received trigger for {} on {}", stack, env);
            ...
        }
    };

    Ok(())
}

Full code

I expected to see this happen:

Bot works fine, if debugged/started, keeps responding until shutdown.

Instead, this happened:

After some time (differs, between 1h and a day) the bot simply does not respond to any commands anymore.

Happens locally or deployed inside the built Docker.

Restarting the bot fixes the problem for a short time. What can I do to keep the bot running better? Any tips to get more debug logs?

One thing I noticed:

Once the internet connection is disconnected/reconnected (happens every day via forced disconnect from my ISP), I get the following errors in the log:

ERROR teloxide::error_handlers > An error from the update listener: Network(reqwest::Error { kind: Request, url: Url { scheme: "https", cannot_be_a_base: false, username: "", password: None, host: Some(Domain("api.telegram.org")), port: None, path: "/token:redacted/GetUpdates", query: None, fragment: None }, source: hyper::Error(Connect, ConnectError("dns error", Os { code: 11001, kind: Uncategorized, message: "Der angegebene Host ist unbekannt." })) })

But the disconnect does not seem to be the problem, if I manually pull my ethernet cable and connect it again after ~2min, the bot works fine.

Meta

  • teloxide version: 0.12.2

Maybe I am using the crate wrong or am missing something? Any pointers are appreciated, thanks

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 20 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I’ll try to reproduce it, what OS are you using?

@syrtcevvi polling timeout must be smaller than http client’s, which is the case (polling_default = 10s, http = 17s), so I don’t think this is the problem…