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
ConcurrentModificationException in getLogs() #21
Comments
Hi Andrey Thank you for mentioning this issue. It looks like it is indeed not thread safe. I think both suggestions sounds as a good solution and I am ok with you creating and submitting a pull request. Looking forward to it! |
I just tried it out it it looks like synchronize will do the trick, just like you suggested by wrapping it with |
Thanks for taking a look! |
Sounds good, I am looking forward to your PR with the |
This makes LogCaptor suitable for using in multi-threaded 'integration' tests
@AndreyNudko I will publish this version in the coming days, I will keep you updated |
@Hakky54 Awesome, thanks for the quick turnaround! |
@AndreyNudko The latest changes are now available within version 2.7.2 |
We tried LogCaptor in some integration-style tests, where logging actually happens in background thread.
Occasionally getLogs() throws
ConcurrentModificationException
-quick look into code shows that
ListAppender.list
is not thread-safe, so it's almost certainly a race between test and application threads. I think it's not a problem for actual logging sinceAppenderBase::doAppend
is synchronized, but it is a problem when scanning the list.One possible fix would be to wrap all access to list into
synchronized(listAppender)
. Or, maybe even better, swap it for CopyOnWrite / Collections::synchronizedList.Any views on that? Happy to submit PR as well.
The text was updated successfully, but these errors were encountered: