Skip to content

Asynchronous initialization causing concurrently problem in DashboardApplication #705

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

Closed
jasonjoo2010 opened this issue Apr 25, 2019 · 2 comments
Labels
kind/bug Category issues or prs related to bug. kind/enhancement Category issues or prs related to enhancement.

Comments

@jasonjoo2010
Copy link
Collaborator

jasonjoo2010 commented Apr 25, 2019

Issue Description

Some racing problem occurred like ConcurrentModification on System.properties

Describe what happened (or what feature you want)

E9B3A872-4232-406d-8976-FE114B2DA775

How to reproduce it (as minimally and precisely as possible)

Calling setProperty putting new keys into property set while InitExecutor.doInit is executed asynchronously.

Discussion

Asynchronism Supporting

We should declare whether asynchronism should be supported here.
We take the answer YES till someone submitted different opinions.

Direct Cause of the Issue

The main method is shown below used by Dashboard booting up.

public class DashboardApplication {

    public static void main(String[] args) {
        triggerSentinelInit();
        SpringApplication.run(DashboardApplication.class, args);
    }

    private static void triggerSentinelInit() {
        new Thread(() -> InitExecutor.doInit()).start();
    }
}

The InitExecutor.doInit() is called in another thread when spring boot is starting.
It may add new keys calling System.setProperty when booting. And we have the code below to load config from properties in SentinelConfig.loadProps:

        // JVM parameter override file config.
        for (Map.Entry<Object, Object> entry : System.getProperties().entrySet()) {
            String configKey = entry.getKey().toString();
            String configValue = entry.getValue().toString();
            String configValueOld = getConfig(configKey);
            SentinelConfig.setConfig(configKey, configValue);
            if (configValueOld != null) {
                RecordLog.info("[SentinelConfig] JVM parameter overrides {0}: {1} -> {2}", configKey, configValueOld, configValue);
            }
        }

Which we may use CopyOnWriteArraySet instead to walk through the values safely.

Is there any opinions, folks?

@sentinel-bot sentinel-bot added the kind/question Category issues related to questions or problems label Apr 25, 2019
@sczyh30 sczyh30 added kind/bug Category issues or prs related to bug. kind/enhancement Category issues or prs related to enhancement. and removed kind/question Category issues related to questions or problems labels Apr 25, 2019
@sczyh30
Copy link
Member

sczyh30 commented Apr 25, 2019

Yes, it's necessary to make it thread-safe.

@sczyh30
Copy link
Member

sczyh30 commented Apr 25, 2019

Fixed in #706

@sczyh30 sczyh30 closed this as completed Apr 25, 2019
CST11021 pushed a commit to CST11021/Sentinel that referenced this issue Nov 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Category issues or prs related to bug. kind/enhancement Category issues or prs related to enhancement.
Projects
None yet
Development

No branches or pull requests

3 participants