Skip to content
This repository was archived by the owner on Aug 13, 2023. It is now read-only.
This repository was archived by the owner on Aug 13, 2023. It is now read-only.

Race Condition in SunshineRepository.getInstance #38

Description

@ronykrell

There is a race condition in the getInstance method in SunshineRepository.java.

Imagine there are 2 threads - A and B - both calling getInstance() and that sInstance is null to start with

Thread A
Checks if sInstance is null. Returns True

Thread B
Checks if sInstance is null. Returns True

Thread A
Obtains the lock and creates a new instance for sInstance. Releases lock

Thread B
Remember Thread B already checked if sInstance was null earlier.
Obtains the lock and creates a new instance for sInstance. Releases lock

There should be a second null check inside the synchronized block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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