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

Bad thread interleaving may causes unexpected crash #146

Open
Alisha-0321 opened this issue Nov 23, 2022 · 0 comments
Open

Bad thread interleaving may causes unexpected crash #146

Alisha-0321 opened this issue Nov 23, 2022 · 0 comments

Comments

@Alisha-0321
Copy link

Describe the bug

It is possible to encounter an unexpected crash due to using the same hashmap (variable name is repository, in WeakHashMapCacheStorage), from different methods. Of these methods, one method puts the value in that repository hashmap, and another method is getting the value for a key. One more method named as clear() is also modifying the hashmap and making it empty. However, there is no synchronization between these three methods. As a result, anytime due to the existence of multiple threads, the program may crash.

Expected behavior
No cash is expected

Additional context
When I investigated the WeakHashMapCacheStorage class, I found that the repository is a shared variable that is used at Line 37, Line 43 and Line 47. Here, unexpected crash or inconsistency may occur if multiple threads interleave.

Environment(please complete the following information):
I ran the test on an Ubuntu 20.04 LTS machine using OpenJDK 1.8.0_312.

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

No branches or pull requests

1 participant