MetricFileNameComparator will throw ArrayIndexOutOfBoundsException when metric log dir has both pid and no-pid files #1023
Labels
area/logging
Issues or PRs related to logging of Sentinel
area/metrics
Issues or PRs related to metrics and monitoring
kind/question
Category issues related to questions or problems
Issue Description
Type: bug report
Describe what happened (or what feature you want)
MetricFileNameComparator will throw ArrayIndexOutOfBoundsException when metric log dir has both pid and no-pid files.
In MetricFileNameComparator.compare() method, when the first comparing filename has the "pid" tag, it also consider the second comparing filename has the pid tag. If the filename do not have, this will lead the ArrayIndexOutOfBoundsException
the file list:
org-codehaus-classworlds-Launcher-metrics.log.2019-08-26.14
org-codehaus-classworlds-Launcher-metrics.log.2019-08-26.15
org-codehaus-classworlds-Launcher-metrics.log.2019-08-26.16
org-codehaus-classworlds-Launcher-metrics.log.2019-08-27
org-codehaus-classworlds-Launcher-metrics.log.pid20760.2019-08-26
org-codehaus-classworlds-Launcher-metrics.log.pid6192.2019-08-26
the exception stack:
2019-08-27 11:42:57 write metric error:
java.lang.ArrayIndexOutOfBoundsException: 3
at com.alibaba.csp.sentinel.node.metric.MetricWriter$MetricFileNameComparator.compare(MetricWriter.java:250)
at com.alibaba.csp.sentinel.node.metric.MetricWriter$MetricFileNameComparator.compare(MetricWriter.java:238)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:355)
at java.util.TimSort.sort(TimSort.java:220)
at java.util.Arrays.sort(Arrays.java:1512)
at java.util.ArrayList.sort(ArrayList.java:1454)
at java.util.Collections.sort(Collections.java:175)
at com.alibaba.csp.sentinel.node.metric.MetricWriter.listMetricFiles(MetricWriter.java:292)
at com.alibaba.csp.sentinel.node.metric.MetricWriter.removeMoreFiles(MetricWriter.java:297)
at com.alibaba.csp.sentinel.node.metric.MetricWriter.closeAndNewFile(MetricWriter.java:312)
at com.alibaba.csp.sentinel.node.metric.MetricWriter.write(MetricWriter.java:136)
at com.alibaba.csp.sentinel.node.metric.MetricTimerListener.run(MetricTimerListener.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset$$$capture(FutureTask.java:308)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Describe what you expected to happen
MetricFileNameComparator.compare() mothed should cover this situation
How to reproduce it (as minimally and precisely as possible)
Tell us your environment
sentinel version: 1.3.0.GA
windows 7
Anything else we need to know?
The text was updated successfully, but these errors were encountered: