-
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
Class loading fails on an interrupted thread causing com.mongodb.event.ServerClosedEvent to fail to load when Mongo detects a cluster change #38611
Comments
Hello! I can't see any code from Boot in the stacktrace, besides the JAR loader. I'm not sure if this has something to do with the Uber JAR rewrite. Can you please try with the classic loader implementation and report back if that fixes the issue? See here for details: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#nested-jar-support |
The connectivity issue with MongoDB "AWS DocumentDB" appears resolved after implementing the classic loader in Spring Boot 3.2.0:
Any additional insights or recommendations moving forward would be appreciated. |
cc @philwebb |
@manjian14 The stack trace would suggest that the problem occurs when there's a change in the topology of the cluster but I haven't been able to reproduce it. Can you please provide a minimal sample and the steps to follow to cause the failure? |
I've configured my application to connect to an AWS DocDB cluster using the standard driver configuration. Below is a snippet from my @Slf4j
@Configuration
@EnableMongoRepositories(value = "com.????")
@ConditionalOnProperty(prefix = "mongo.connection", value = "string")
public class MongoDbConfiguration extends AbstractMongoClientConfiguration {
@Value("${mongo.connection.string}")
private String connectionString;
@Override
@Primary
@Bean
public @NonNull MongoClient mongoClient() {
return MongoClients.create(connectionString);
}
@Override
protected @NonNull String getDatabaseName() {
return "???";
}
} In this setup, I've embedded the username and password within the cluster URL. The cluster has two replica sets, one for reading and one for writing. Additionally, the database is not accessible from outside; access is restricted either by whitelisted IP addresses or by project roles within the ECS cluster. The AWS DocDB version is 5.0.0, the latest version as per AWS recommendations. The project is using Gradle version 8.5 and Java version 17. The base image is amazoncorretto:17-al2023-headful, and during the image build process, I've imported the SSL certificate using the keytool tool. If you have any specific questions or if there's anything else you'd like to know, feel free to ask! |
@manjian14 Is there any chance you could switch back to the |
I tried using 3.2.1-SNAPSHOT, but ran into a problem—' springboot binaries are incompatible with your platform' |
What platform are you using? It's rather unfortunate that it apparently won't allow you to test snapshot artifacts. |
Seeing the same error with our own MongoDB cluster(s) deployed to our own Kubernetes starting with Spring Boot 3.2.0.
I'll give it a try with 3.2.1-SNAPSHOT. |
Same thing with
|
The errors are gone when using |
@msievers Are you able to provide a sample application that we can debug? |
@philwebb I'll give it a try and ping you once I got it. As I cannot take one of our company apps where I see this happen, I hope it can be reproduced with some simple playground app. |
As an alternative to switching back to the classic loader implementation, another workaround is to load the class up front: @SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
Class.forName("com.mongodb.event.ServerClosedEvent");
SpringApplication.run(Application.class, args);
}
} |
This is another variant of #38154, but this time allowing the interruption to continue by rethrowing the |
We've just pushed a fix for this. It would be much appreciated if someone could try the latest 3.2.1 SNAPSHOT with the default loader to see if we've fixed the problem. |
@philwebb I'll give it a try and report back. |
@philwebb It's still failing with 3.2.1-SNAPSHOT. Was the last CI build completed successfully? It's orange, maybe the changes were not published/pushed, see https://ci.spring.io/teams/spring-boot/pipelines/spring-boot-3.2.x/jobs/build/builds/802 |
Gahh, those failures are a pain. It wasn't published but I also didn't get a notification. I've kicked it off again and I'll comment back here when it's done. Sorry about that. |
Sorry @msievers, we're having some trouble with our CI right now and we haven't managed to publish jars yet. |
@msievers Our CI's been fixed and a new snapshot 3.2.1-SNAPSHOT build has been published. Could you please give it a try if you have the time? |
@philwebb @wilkinsona I can confirm that for my two use cases, one being our internal application and the other the application I created on GitHub to reproduce the error, the issue seems to have disappeared with the use of the current Spring Boot 3.2.1-SNAPSHOT version. |
Thank you, @msievers. That's some greatly appreciated good news. |
https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.2-Release-Notes#nested-jar-support ticket to follow: spring-projects/spring-boot#38611 once 3.2.1 is out, try removing CLASSIC loaderImplementation setting in spring-boot-maven-plugin
Refine the fix for gh-38611 so that `ClosedByInterruptException` no longer retries in a loop. Our previous fix was flawed due to the fact that another interrupt could occur after we clear the first and whilst we are reading data. If this happens 10 times in a row, we raise an exception and end up causing NoClassDefFoundError errors. Our new approach retains the use of `FileChannel` and a direct buffer up to the point that a `ClosedByInterruptException` is raised or the thread is detected as interrupted. At that point, we temporarily switch to using a `RandomAccessFile` to access the data. This will block the thread until the data has been read. Fixes gh-40096
We've encountered a connectivity problem after migrating from Spring Boot 3.1.5/3.1.6 to 3.2.0. The error log points to a missing class:
java.lang.ClassNotFoundException: com.mongodb.event.ServerClosedEvent
This is affecting our connection to MongoDB "AWS DocumentDB." Any guidance or resolution on this matter would be greatly appreciated.
The text was updated successfully, but these errors were encountered: