Skip to content

Wrong use of "scheduleAtFixedRate" in consumer client code #3860

@MatrixHB

Description

@MatrixHB

In consumer client code ConsumeMessageConcurrentlyService, there is a scheduled executor used to clean the expired messages(consuming-blocked messages) in ProcessQueue.

this.cleanExpireMsgExecutors.scheduleAtFixedRate(new Runnable() {

            @Override
            public void run() {
                cleanExpireMsg();
            }

        }, this.defaultMQPushConsumer.getConsumeTimeout(), this.defaultMQPushConsumer.getConsumeTimeout(), TimeUnit.MINUTES);

When using scheduleAtFixedRate, once a thread throws an exception, it will not continue to execute the following threads. So the Runnable must be surrounded by try-catch.

Since the scheduleAtFixedRate without try-catch, the cleanExpireMsg thread may abnormally exit and never be executed again, which may cause the consuming-blocked message always stay in ProcessQueue, resulting in the consume offset get stuck. (We have actually met this problem in production environment.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions