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

race condition in Log4jAdapterLabelPrinter #74

Closed
thgau opened this issue Oct 20, 2021 · 3 comments · Fixed by #78
Closed

race condition in Log4jAdapterLabelPrinter #74

thgau opened this issue Oct 20, 2021 · 3 comments · Fixed by #78
Assignees
Labels
log4j2-appender Relates to Log4j2 Appender component

Comments

@thgau
Copy link

thgau commented Oct 20, 2021

There is a problem with multiple threads in class Log4jAdapterLabelPrinter.
The StringBuilder allocated there is shared between threads. It might happen that the threads corrupt the data if both are using it at the same time.
I think the StringBuffer should be allocated once per Thread and kept in a ThreadLocal storage.
Best Regards,
thgau

@thgau thgau changed the title raze condition in Log4jAdapterLabelPrinter race condition in Log4jAdapterLabelPrinter Oct 20, 2021
@tkowalcz
Copy link
Owner

Hi,

thanks a lot for reporting. I can confirm it, and it is quite obvious when someone points it out. I will try to push a fix today.

@tkowalcz tkowalcz added the log4j2-appender Relates to Log4j2 Appender component label Oct 20, 2021
@tkowalcz tkowalcz self-assigned this Oct 20, 2021
tkowalcz added a commit that referenced this issue Oct 20, 2021
…ocal StringBuilder in Log4jAdapterLabelPrinter that can be shared between many threads.
@tkowalcz tkowalcz linked a pull request Oct 21, 2021 that will close this issue
@tkowalcz
Copy link
Owner

I have released version 0.9.18 that should fix this. I will appreciate if you could verify this works now.

@thgau
Copy link
Author

thgau commented Oct 24, 2021

Great, it works! Thanks for the fix.

@thgau thgau closed this as completed Oct 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
log4j2-appender Relates to Log4j2 Appender component
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants