Skip to content

Loading of custom deny-all filter can cause a StackOverflowError when deploying to Tomcat with Log4j2 configured to use a single JVM-wide logger context #40235

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

Closed
wants to merge 1 commit into from

Conversation

ppkarwasz
Copy link
Contributor

This PR replaces the custom "deny all" filter used by Log4J2LoggingSystem with the standard DenyAllFilter, which is available since Log4j Core 2.13.0.

The purpose of this change is:

  • to simplify the code base,
  • to work around a pesky interaction between the custom Spring Boot filter and Tomcat's classloader (cf. StackOverflowException in Logger.isEnabled with Spring Boot 3 + Tomcat apache/logging-log4j2#1430). If Log4j Core is configured to use a single logger context for the whole JVM, Spring Boot will add its custom filter implementation (contained in Spring Boot's classloader) to the global logging system. Since Tomcat's classloader performs logging calls, this will cause a StackOverflowException while attempting to resolve the filter class. Using a class from Log4j Core (which must be in the system classloader in this configuration) will work around the problem.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 9, 2024
@wilkinsona wilkinsona changed the title Replace custom Log4j Core filter with DenyAllFilter Loading of custom deny-all filter can cause a StackOverflowError when deploying to Tomcat with Log4j2 configured to use a single JVM-wide logger context Apr 9, 2024
@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 9, 2024
@wilkinsona wilkinsona added this to the 3.1.x milestone Apr 9, 2024
@wilkinsona
Copy link
Member

Thanks very much, @ppkarwasz.

@ppkarwasz ppkarwasz deleted the fix/deny-filter branch April 10, 2024 19:33
@ppkarwasz
Copy link
Contributor Author

You're welcome, @wilkinsona.

There are still some small adjustments to the Log4j2LoggingSystem I would like to contribute in preparation for the upcoming Log4j Core 3.x release (e.g. a fix of apache/logging-log4j2#1799). Any chance we can make it in time for Spring Boot 3.3.0? Or should we rather target Spring Boot 3.4.0?

Remark: Personally I would prefer to keep the current 2.x version of log4j-to-slf4j in Log4j 3.x instead of releasing a 3.0.0 for that artifact (see this thread on dev@logging). This would certainly ease the upgrade of the log4j2.version property to 3.0.0, since it would not change anything in the default spring-boot-starter-logging artifact.

@wilkinsona
Copy link
Member

3.3.0-RC1 is scheduled for next week. Depending on the nature of the changes that means we may only have a week to make any further changes. If it's a bug, we have longer as we can make the fix post RC1 or even in a subsequent maintenance release.

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

Successfully merging this pull request may close these issues.

3 participants