Skip to content

🐞 [Bug] org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer#updatesProcessorExecutor should not be a static variable #1563

@yvasyliev

Description

@yvasyliev

Describe the bug

Since org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer#updatesProcessorExecutor is a static variable, it's not safe to use LongPollingSingleThreadUpdateConsumer for two or more bots within the same application.

If bot_1 shuts down updatesProcessorExecutor, it's gets shut down for the bot_2 too.

To Reproduce

Minimal reproducible example: yvasyliev/telegram-bot-update-handler-demo

  1. Run the application: ./gradlew run --args="$BOT_TOKEN_1 $BOT_TOKEN_2"
  2. Send /start and /stop commands to the first bot.
  3. Send /start command to the second bot.

ER: the second bot should log incoming message
AR: the second bot does nothing

Expected behavior

The second bot should continue working regardless of whether the first bot shut down the executor service or not.

Suggested solution:

  1. Remove updatesProcessorExecutor from LongPollingSingleThreadUpdateConsumer
  2. Rename LongPollingUpdateConsumer to LongPollingUpdatesConsumer
  3. Rename LongPollingSingleThreadUpdateConsumer to LongPollingUpdateConsumer

This way, it's up to user how they want to handle the updates (sync (default) or async).

Screenshots

Image

Desktop (please complete the following information):

N/A

Smartphone (please complete the following information):

N/A

Additional context

Additional motivation: updatesProcessorExecutor is never shut down explicitly in the existing implementation which may result in resource leaks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions