-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Spring Boot remote restart with devtools causes 'factory already defined' Tomcat error when running with 'java -jar' #39733
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
Comments
Thanks for the report. We have integration tests for restarts with both a local application and a remote application. The app that's used for tests uses Tomcat and all of the tests are passing. In short, we're not aware of any general problems with the remote restart support so there must be something specific to your usage of it that is causing it to break.
Unfortunately, we don't have time to use such a complex reproducer as there are too many moving parts. Any one of them could be causing the problem, not just Spring Boot. If you would like us to spend some more time investigating, please provide a reproducer that contains the bare minimum that's needed to reproduce the problem. The process of producing this reproducer may identify an external cause which can then be addressed by the relevant maintainers. If it identifies Spring Boot as the cause we can then take another look and see why our existing tests didn't catch the problem. |
Hi @wilkinsona, I managed to create a fairly simple end to end (e2e) test project that consistently reproduces the issue. You should be able to clone the project and run If you carefully review the CI logs, you'll notice that with version 2.7.11, the test does pass: However, for the 2.7.12 version the test fails (I assume it will be the same for any 3.x.x version too): I configured the test to print out the log of the remote application, we can see here the stacktrace I mentioned in the issue description:
Regarding the integration test you linked, I'm not sure if it applies to the current scenario (Remote Update). I do see there's a RemoteApplicationLauncher, but this one doesn't contain a test scenario for the update feature either. P.S. I saw there was a link to the integration tests after bootstrapping my own project and working on the complete implementation 🤦. I would have worked on the original repo otherwise, sorry. |
I am pretty sure that it does. Every test in that class is making an update to the application. The tests are run in three different ways:
Spring Boot 2.7.x is out of OSS support. Do you know that it fails with 3.x.x or is this just an assumption? |
As I said, I just gave an overall look, I surely missed it. I assumed it was just testing with local application. Since it's an integration test (no apparent separate process invocations) it's hard (for me) to understand what's really going on.
Not an assumption, it has the same failure https://github.com/marcnuri-work/spring-projects-spring-boot-issues-39733/actions/runs/8115267126/job/22182771368#step:4:1942 (I just added 3.2.0 to the test suite). P.S. BTW learning that end of commercial support for 2.x (i.e. Java 8) is mid 2025 just killed me, for some reason I thought it was mid-2024 when it would be over 😭, |
I can confirm that remote update indeed doesn't work. I've tested with 3.2.5 and 3.3.0-SNAPSHOT. The connection to the remote application works, but as soon as I change something, the change is sent to the remote application and then the application crashes. This seems to be a Tomcat problem, if I switch to Jetty, it works. |
3.0.6 works. Others versions that do not work with tomcat, with jetty do not craches but do not update the code. |
I can replicate the issue using Spring Boot 2.7.12 with both Tomcat and Spring Framework downgraded which makes me think it's something in Spring Boot itself that's causing the problem. The cause appears to be the fact that There's nothing jumping out in the diff between 2.7.11 and 2.7.12 |
I think I've finally got to the bottom of this one. I think #35214 is responsible for the problem. In Spring Boot 2.7.11 the restart class is detected as the users SpringApplication class. For example:
In 2.7.12, when running as an uber jar it's the launcher class:
The result of this is that an entire new launcher is restarted resulting in a newly loaded |
I've tried a fix in 3.2 to ignore loader classes. The sample works if
|
The |
After a lot of digging I've managed to discover the a change in Spring Framework is breaking class enhancement. I've raised spring-projects/spring-framework#33024 to see if we can fix that. |
I've pushed a fix for our side of the problem. We'll pick up the Framework fix in due course. |
Reopening to manually test once the Framework fix is in. |
It seems to be fixed with the latest Framework release. |
Awesome job, thanks for taking care of this 🙌🚀 |
Description
Starting on v2.7.12 (last working version was v2.7.11) and up to any 3.x.x version Spring Boot Remote has stopped working.
Whenever a remote session is started and changes are detected, Spring Remote tries to restart the application but the application can't start.
Spring Remote output
Application output
Click to expand detailed output
Relevant pieces:
Expected application output
Click to expand
According to other issues with reference to the "factory already defined" error, it seems that Tomcat uses a static to ensure that
setURLStreamHandlerFactory
is only called once. However, it does seem that this shouldn't be applicable, or should be specifically tackled, for the remote dev tools.As a reproducer project you can use JKube's Spring Boot Watch quickstart and a local Kubernetes cluster such as Minikube. Changing the Spring Boot Starter Parent version to anything beyond 2.7.12 should reproduce the problem.
Relates to:
The text was updated successfully, but these errors were encountered: