Skip to content

Bad thread interleaving may causes unexpected crash #146

@Alisha-0321

Description

@Alisha-0321

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions