reo7sp / tgbot-cpp

C++ library for Telegram bot API

Home Page:http://reo7sp.github.io/tgbot-cpp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Telegram Error: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running

StormLord07 opened this issue · comments

There was some problem with longpoll which caused segfault or the thread to just be locked, not receiving/posting any requests like in this Issue I tried to do the most sensible thing and just wrap it in the try-catch

        try {
            std::cout << "Bot username: @" << bot->getApi().getMe()->username << std::endl;
            TgBot::TgLongPoll longPoll(*bot);

            int retryCount = 0;
            while (true) {
                try {
                    longPoll.start();
                    retryCount = 0;  // Reset retry count after successful start
                }
                catch (const boost::system::system_error& e) {
                    if (retryCount < MAX_RETRIES) {
                        std::cerr << "Boost System Error: " << e.what() << ". Retrying in " << RETRY_WAIT_TIME << " seconds." << std::endl;
                        std::this_thread::sleep_for(std::chrono::seconds(RETRY_WAIT_TIME));
                        retryCount++;
                    } else {
                        std::cerr << "Max retries reached. Exiting." << std::endl;
                        throw;  // Re-throw the exception to the outer catch block
                    }
                }
            }
        }
        catch (const TgBot::TgException &e) {
            std::cerr << "Telegram Error: " << e.what() << std::endl;
        }
        catch (const std::exception& e) {
            std::cerr << "Standard Exception: " << e.what() << std::endl;
        }
        catch (...) {
            std::cerr << "Unknown exception caught." << std::endl;
        }
        ```
        
        which now causes `Telegram Error: Conflict: terminated by other getUpdates request; make sure that only one bot instance is running`
        or just "Standart Exception" with e.what being something unreadable, maybe I'm doing something wrong, but the problem seems to be with how longpoll works.