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

sentinel-dashboard TreeMap ConcurrentModificationException #201

Closed
huangxfchn opened this issue Oct 26, 2018 · 1 comment · Fixed by #205
Closed

sentinel-dashboard TreeMap ConcurrentModificationException #201

huangxfchn opened this issue Oct 26, 2018 · 1 comment · Fixed by #205
Labels
area/dashboard Issues or PRs about Sentinel Dashboard kind/bug Category issues or prs related to bug.
Milestone

Comments

@huangxfchn
Copy link
Contributor

huangxfchn commented Oct 26, 2018

Issue Description

When I use the dashboard, 'MetricFetcher' throws a ConcurrentModificationException and requests the home page, Jackson also throws the same exception.

Describe what happened (or what feature you want)

Here is the exception stack traces:

2018-10-26 14:58:00 [sentinel-dashboard-metrics-fetchWorker-thread-59] INFO  c.t.c.s.d.metric.MetricFetcher - fetchOnce(spark-feature-online) error
java.util.ConcurrentModificationException: null
        at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1211)
        at java.util.TreeMap$KeyIterator.next(TreeMap.java:1265)
        at com.taobao.csp.sentinel.dashboard.metric.MetricFetcher.fetchOnce(MetricFetcher.java:185)
        at com.taobao.csp.sentinel.dashboard.metric.MetricFetcher.lambda$doFetchAppMetric$3(MetricFetcher.java:258)

and

2018-10-26 14:57:44 [http-nio-9090-exec-7] ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: (was java.util.ConcurrentModificationException); nested exception is com.fasterxml.jackson.databind.JsonMappingException: (was java.util.ConcurrentModificationException) (through reference chain: com.taobao.csp.sentinel.dashboard.view.Result["data"]->java.util.ArrayList[3]->com.taobao.csp.sentinel.dashboard.discovery.AppInfo["machines"]->java.util.TreeSet[378])] with root cause
java.util.ConcurrentModificationException: null
        at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1211)
        at java.util.TreeMap$KeyIterator.next(TreeMap.java:1265)
        at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:133)
        at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:112)
        ......
        at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:951)
        at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:286)
        at org.springframework.http.converter.AbstractGenericHttpMessageConverter.write(AbstractGenericHttpMessageConverter.java:106)
        at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:231)
        at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.handleReturnValue(RequestResponseBodyMethodProcessor.java:174)
        ......
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)

Describe what you expected to happen

AppInfo uses synchronized for the getMachines and addMachine methods, but calls the getmachines method to get the same TreeSet, so there is no guarantee that Set<MachineInfo> machines = new TreeSet<MachineInfo >(); is modified by multiple threads, so it is very likely that a ConcurrentModificationException exception will be thrown.

However, I did not find that the Set<MachineInfo> was modified by calling the getmachines method.

Here is the code for AppInfo

public class AppInfo {

    private Set<MachineInfo> machines = new TreeSet<MachineInfo>();

    public synchronized Set<MachineInfo> getMachines() {
        return machines;
    }

    public synchronized boolean addMachine(MachineInfo machineInfo) {
        machines.remove(machineInfo);
        return machines.add(machineInfo);
    }

}

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

  1. When calling the getMachines method, create a new TreeSet to avoid concurrency issues.
@sczyh30 sczyh30 added the kind/bug Category issues or prs related to bug. label Oct 26, 2018
@sczyh30
Copy link
Member

sczyh30 commented Oct 26, 2018

Thanks for reporting. We'll fix and validate it.

@sczyh30 sczyh30 added this to the 1.3.0 milestone Oct 26, 2018
@sczyh30 sczyh30 added the area/dashboard Issues or PRs about Sentinel Dashboard label Oct 26, 2018
CST11021 pushed a commit to CST11021/Sentinel that referenced this issue Nov 3, 2021
[ROCKETMQ-324] Expose an interface for client to specify the async call back executor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dashboard Issues or PRs about Sentinel Dashboard kind/bug Category issues or prs related to bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants