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

java.lang.IllegalArgumentException: negative size: -83 #5169

Closed
3 tasks done
DaiChaoLi opened this issue Jul 2, 2024 · 7 comments
Closed
3 tasks done

java.lang.IllegalArgumentException: negative size: -83 #5169

DaiChaoLi opened this issue Jul 2, 2024 · 7 comments
Labels

Comments

@DaiChaoLi
Copy link

DaiChaoLi commented Jul 2, 2024

描述bug

这里已经有相关描述 #4356

我这里一下细节,Apoll 1.9.2 Guava-31.1-jre,这个很重要,因为SpringValueRegistry在Apoll 2.1之后删了,Guava在比较低的版本没办法重现问题

复现

因为比较难复现,所以来求助社区看看有没有办法复现出来,如上描述的情形。

这里给一个触发场景大致是这样的,一般项目都会封装一个SpringBeanAwareUtil,然后getBean,多线程进行getBean中,会走这段逻辑

at com.ctrip.framework.apollo.spring.annotation.SpringValueProcessor.processField(SpringValueProcessor.java:105) at com.ctrip.framework.apollo.spring.annotation.ApolloProcessor.postProcessBeforeInitialization(ApolloProcessor.java:39) at com.ctrip.framework.apollo.spring.annotation.SpringValueProcessor.postProcessBeforeInitialization(SpringValueProcessor.java:83) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:440) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1154)

这样就形成了,多线程在register中put,然后另外线程scanAndClean remove,最后触发

java.lang.IllegalArgumentException: negative size: -83 at com.google.common.base.Preconditions.badPositionIndex(Preconditions.java:1409) at com.google.common.base.Preconditions.checkPositionIndex(Preconditions.java:1400) at com.google.common.base.Preconditions.checkPositionIndex(Preconditions.java:1382) at com.google.common.collect.LinkedListMultimap$NodeIterator.<init>(LinkedListMultimap.java:334) at com.google.common.collect.LinkedListMultimap$1EntriesImpl.listIterator(LinkedListMultimap.java:836) at java.base/java.util.AbstractList.listIterator(AbstractList.java:311) at java.base/java.util.AbstractSequentialList.iterator(AbstractSequentialList.java:238) at com.google.common.collect.Synchronized$SynchronizedCollection.iterator(Synchronized.java:179) at com.ctrip.framework.apollo.spring.property.SpringValueRegistry.scanAndClean(SpringValueRegistry.java:87) at com.ctrip.framework.apollo.spring.property.SpringValueRegistry.access$000(SpringValueRegistry.java:36) at com.ctrip.framework.apollo.spring.property.SpringValueRegistry$1.run(SpringValueRegistry.java:75) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833)

期望

简介明了地描述你希望正常情况下应该发生什么

截图

如果可以,附上截图来描述你的问题

额外的细节和日志

  • 版本:
  • 错误日志
  • 配置:
  • 平台和操作系统
@DaiChaoLi
Copy link
Author

仔细看了下,只要spring bean是多例,那么就会存在,多线程进行put和定时器线程进行remove的并发修改操作

@nobodyiam
Copy link
Member

是否能稳定复现?之前也有 issue 提及 #4800

@DaiChaoLi
Copy link
Author

是否能稳定复现?之前也有 issue 提及 #4800

这个并发异常有两个的,一个是java.lang.IllegalArgumentException: negative size这种,一个是ConcurrentModificationException,但是本质上是同一个问题。发现后者是比较容易稳定复现的,前者比较难。你只需要把spring的bean搞成多例,然后多线程get bean,这样形成bean不断的在创建和销毁的情况。就比较容易观察到了,要是还是不行,我再上传demo,理论上按照我前面的描述很容易构造出demo

@DaiChaoLi
Copy link
Author

还要补充一点,就是这个多例的bean里面要有@value,不然走不到这个流程

@nobodyiam
Copy link
Member

尝试了多次未能复现,是否方便上传个 demo?

Copy link

stale bot commented Aug 28, 2024

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 28, 2024
Copy link

stale bot commented Sep 6, 2024

This issue has been automatically closed because it has not had activity in the last 7 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants