apache / rocketmq

Apache RocketMQ is a cloud native messaging and streaming platform, making it simple to build event-driven applications.
https://rocketmq.apache.org/
Apache License 2.0
21.26k stars 11.7k forks source link

[Bug/Typo] Write lock not released in IndexStoreService #8688

Open imzs opened 2 months ago

imzs commented 2 months ago

Before Creating the Bug Report

Runtime platform environment

All

RocketMQ version

5.x

JDK Version

All

Describe the Bug

I run the unit test of our local branch, but found that the test can't be finished after all test passed. After a long time of debugging step by step, I found this.

} catch (Exception e) {
       log.error("IndexStoreService force upload error", e);
       throw new RuntimeException(e);
} finally {
       readWriteLock.writeLock().lock();
}

I would call it a typo rather than a bug.

Steps to Reproduce

*

What Did You Expect to See?

*

What Did You See Instead?

*

Additional Context

Well, let's talk about something else.

This weakness is classified as [Incomplete Cleanup], see details in https://cwe.mitre.org/data/definitions/459

Why didn't we find it early? Is there any tool to help? Sonar plugin or Github Copilot? As a rule based static code analysis tool, SonarLint failed to find this bug. I've not aware of SonarCloud and SonarQube, since I didn't try them. The java rule set can be found here https://rules.sonarsource.com/java/

What's more interesting and exciting is, LLMs seem to solve this easily. I've tried several of them, result like this: image

So, Power of AI! And we're encouraged to utilize them.