-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
Undertow throws exception on shutdown when using Log4j2 #33450
Comments
Can be reproduced using this: |
I also get errors with Undertow when is shutting down but with HikariDataSource:
|
This comment was marked as resolved.
This comment was marked as resolved.
I am encountering the same issue in tests. Using SpringBoot 3.0.3, JUnit5, and gradle 7.4.2.
Any insights would be much appreciated. |
#35184 is somewhat related to this. A fix for 35184 may change how things behave here too. If it doesn't solve the problem (I suspect that it won't), we may have to see if it's possible to remove the |
I just saw this and will look into whether this can be addressed in Log4j itself. I am seeing a different, but related, error when shutting down a sample Spring Boot app. |
I have two fixes for this in my branch:
I think c52ad97 is the cleaner solution, but this does not only remove the |
I have a fix for this in Log4j that I am testing. It simply catches the exception and ignores the PropertySource. However, testing has been difficult as I am trying to upgrade one of my existing services from Spring Boot 2 to Spring Boot 3 and it is painful. |
Sorry to hear that. If there are things missing from https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide please let us know by opening an issue. The guide works best when upgrading from 2.7.x to 3.0.x. From there you can then upgrade to 3.1.x. |
@wilkinsona The issue is just that we have several support libraries that have to be upgraded. One uses the openapi generator so that has to be upgraded and have issues fixed. Then I have to figure out how to modify our CI system to be able to release the library while still supporting Spring 2 (i.e. - a different branch is needed which our CI wasn't designed for). Just a big can of worms. Nothing you can help with. Most of this is Oracle's fault for inflicting the package renaming on us. |
I ended up creating unit tests and verifying the fix without Spring since the issue was easy to reproduce. See apache/logging-log4j2#2062. This will be available in our next Log4j 3.x beta release for testing. 3.x is specifically targeted for Java 17 and Spring Boot 3.x. The fix can be tested now if you use a Log4j 3.x SNAPSHOT. |
Log4j 3.0.0-beta1 has been releaesd. Please try with that version to verify the problem has been resolved. |
I can confirm that using Boot 3.3.0-SNAPSHOT with Log4J2 3.0.0-beta1 fixes this problem. |
Is there any plan to port the changes to log4j2 2.x with Spring boot 3.2 version? |
We are going to have to since we have decided to continue using Log4j-API 2.x with Log4j 3.x when 3.x is released. |
@rgoers @mhalbritter Yet the JVM stuck in native method:
where the
are from some generated code that I'm not faimiliar with either. Meanwhile the perf top shows top symbols called are
I cannot tell if this is the continuation of the same problem, or it's a new problem with log4j2 or undertow or springboot. Any insights will be much appreciated. |
The hang's also been seen by another user. It looks to me like a different symptom of the same problem. The fact that the JVM's apparently getting stuck when Undertow's trying to throw the exception renders the fix in Log4j2 ineffective. We may have to look at an alternative that stops the exception being thrown in the first place. |
Looking more closely at the hang that can be reproduced using the app provided in #40178, it isn't actually a hang but what appears to be an infinite loop in while (source != null) {
result = sourceGetProperty(source, contextKey);
if (result != null) {
return result;
}
source = sources.higher(source);
}
I'm not sure why there are two instances of The presence of the two instances is, as far as I can tell, due to Devtools. The first instance is added when the app starts and the second is added when a change is made that triggers a restart. We need to clean up |
I'm going to re-open #40178 as, unlike the problem reported through this issue, the problem isn't specific to Undertow. |
This comment was marked as duplicate.
This comment was marked as duplicate.
@wilkinsona Thank you for the check. I tried the hack you mentioned in the other issue, yet it didn't help in my case. If I'm understanding it correctly, Undertow is using jboss logging by default and will generate some internal logger instance during the runtime, so the hack for Log4j2 is not working. Yet I believe Undertow accepts properties file to configure the logging provider, through which we can provide log4j as the logging provider, thus we can try resolve it using methods mentioned in #40178, but is it possible to pass the configuration from application.properties? |
@koww I'm not sure why it hasn't worked in your case as, judging by the stack trace, it appears to be the same. Perhaps you can share some code that reproduces your problem so we can investigate further. |
sample.zip
And if you disable one of the test classes the build will pass. |
That zip seems to contain only a
|
@wilkinsona My bad. Please see this file: |
You've configured the workaround in your application's main method but your tests aren't configured to use it. You can correct that like this:
Alternatively, you can upgrade from 3.3.0-M2 to 3.3.0-RC1 and pick up the fix for #40327 so the workaround is no longer needed. With either of these changes in place, |
Revisiting @mhalbritter's reproducer and the sample shared above modified to use Log4j 2.x, the fix for #40178 has fixed this problem too. If you're affected by this problem please upgrade to Spring Boot 3.1.11, 3.2.5, or later. |
@wilkinsona |
When I shutdown serivce, has this.
Work with Spring boot 3.0.0, Undertow and Log4j2
The text was updated successfully, but these errors were encountered: