-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
[BUG]关于SpringValueRegistry.scanAndClean方法报并发修改异常的疑问 #5296
Comments
Hey, @lzbjut! I'm here to help you with any bugs, questions, or contributions you have in mind. Let's work together to resolve any issues you're facing. The issue you're encountering with the In your test case, you managed to reproduce the concurrency issue by performing concurrent writes and periodic cleanups on the multimap. The error you encountered, such as a "negative size" exception, is indicative of concurrent modifications without proper synchronization. To resolve this, you added a This pattern of manually synchronizing access to collection views is crucial when using synchronized multimaps in a concurrent environment. It ensures that all operations on the multimap are performed atomically, maintaining data consistency and preventing runtime errors. To continue talking to Dosu, mention @dosu. Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other |
非常感谢,看来找到根因了 |
Describe the bug
最近使用旧版apollo时遇到prototype-bean导致内存被打满的问题,查找issue找到#1670
在查看相关方法时,找到了遇到并发问题并解决的:#2281
但是查看SpringValueRegistry类的issue还是发现了:#4355、#4356、#4800、#4925、#5169
问题主要集中于scanAndClean还是有报并发错误,我查看synchronizedListMultimap方法的注释时,发现有相关叙述:
其中It is imperative that the user manually synchronize on the returned multimap when accessing any of its collection views:
Failure to follow this advice may result in non-deterministic behavior.
是否说明synchronizedMultimap的iterator实际上是非线程安全的,于是我就尝试自己写了一个简单的复现代码,并获得了其他issue中提到的错误
To Reproduce
复现这个synchronizedMultimap并发写入并定期清理导致报错的场景,我复现出其中一种,即输入固定量的k-v,定时清除,在写入停止后,因为剩余值(registry.entries().size())为负,在获取iterator时会报错:negative size
Additional Details & Logs
当我为清理代码增加synchronized后该问题解决:
The text was updated successfully, but these errors were encountered: