Skip to content

SpringApplication.exit(...) not closing application due to MongoDB locks for cluster with multiple nodes #4711

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
infoShare opened this issue May 29, 2024 · 0 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@infoShare
Copy link

infoShare commented May 29, 2024

When using simple application with spring boot web app and spring-data-mongodb connected to MongoDB cluster with multiple nodes SpringApplication.exit(...) is usually not closing application due to locks (for example - GC execution is releasing lock).

Sample application:

@SpringBootApplication
public class SpringDataMongodbSSL {

    public static void main(String[] args) {
        SpringApplication.run(SpringDataMongodbSSL.class, args);
    }


    @EventListener(ApplicationReadyEvent.class)
    public void close(ApplicationReadyEvent event) {
        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("Closing context");
                SpringApplication.exit(event.getApplicationContext(), () -> 0);
                System.out.println("Context closed");
            }
        }, 15 * 1000);
    }
}

Configuration on application.yml contain only mongo uri and server.shutdown=graceful to print shutdown on the console (behavior the same without this property).

Execution logs:

Discovered replica set primary DB_URL:27017 with max election id 7fffffff0000000000000026 and max set
Closing context
Commencing graceful shutdown. Waiting for active requests to complete
Graceful shutdown complete
Context closed

And then application is still running.

Profiling results:
image

Repository with example: Repository
Spring Boot: 3.3.0
Java: 21

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants