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

MetricFileNameComparator will throw ArrayIndexOutOfBoundsException when metric log dir has both pid and no-pid files #1023

Closed
wh88725 opened this issue Aug 27, 2019 · 4 comments
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

Comments

@wh88725
Copy link

wh88725 commented Aug 27, 2019

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)

  1. use -Dcsp.sentinel.log.use.pid=true to run a while to generate files contains pid
  2. delete the property to run a while
  3. the exception appear in sentinel-record.log

Tell us your environment

sentinel version: 1.3.0.GA
windows 7

Anything else we need to know?

@sczyh30
Copy link
Member

sczyh30 commented Aug 27, 2019

Hi, is this reproducible with the latest 1.6.3 version?

@wh88725
Copy link
Author

wh88725 commented Aug 27, 2019

I didn't test it in 1.6.3. I just read the latest MetricFileNameComparator and it has no change.
if the latest version fix it in another way, i can try it.

@sczyh30 sczyh30 added area/logging Issues or PRs related to logging of Sentinel area/metrics Issues or PRs related to metrics and monitoring kind/bug Category issues or prs related to bug. kind/question Category issues related to questions or problems and removed kind/bug Category issues or prs related to bug. labels Aug 27, 2019
@sczyh30
Copy link
Member

sczyh30 commented Aug 28, 2019

This might have been fixed by #331. You have to ensure whether this bug can be reproduced in the latest version.

@wh88725
Copy link
Author

wh88725 commented Aug 28, 2019

OK. I will try it later.

@wh88725 wh88725 closed this as completed Aug 28, 2019
CST11021 pushed a commit to CST11021/Sentinel that referenced this issue Nov 3, 2021
…aba#1023)

* update: the period to a comma

* Update Concept.md

* Update Concept.md
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants