Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
MatrixHB opened this issue Feb 18, 2022 · 0 comments
Closed

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

MatrixHB opened this issue Feb 18, 2022 · 0 comments

Comments

@MatrixHB
Copy link
Contributor

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants