Shutdown gracefully
ServiceComb achieve graceful shutdown through JDK's ShutdownHook.
Scenes
Graceful shutdown can solve the following scenes:
- KILL PID
- Application automatically exits unexpectedly(System.exit(n))
Graceful shutdown can't solve the following scenes:
- KILL -9 PID or taskkill /f /pid
Effect
When triggering graceful shutdown:
- Provider:
- Mark the current service status as STOPPING, do not accept new client requests, the new request will report error directly on the client, and the client cooperates with the retry mechanism to retry other instances;
- Wait for the currently running thread to finish executing. If the provider side has set timeout, will be forced to close after timeout;
- consumer:
- Mark the current service state as STOPPING, do not send a new call request;
- Waiting for the response of the currently sent request, if it exceeds the timeout period for the client to receive the response (default 30 seconds), it is forcibly closed;
Principle
When an graceful shutdown is triggered, the following steps are performed in sequence:
- Send a BEFORE_CLOSE event to all listeners, and notify the listener to handle the corresponding event;
- Mark the current service status as STOPPING;
- Log out the current microservice instance from the service center and close the vertx corresponding registry;
- Waiting for all currently existing invocation calls to complete;
- Close the vertx corresponding to config-center and transport;
- Send an AFTER_CLOSE event to all listeners, and notify the listener to handle the corresponding event;
- Mark the current service status as DOWN; graceful shutdown ends;