AlbumenJ commented on code in PR #10730:
URL: https://github.com/apache/dubbo/pull/10730#discussion_r992920247
##########
dubbo-common/src/main/java/org/apache/dubbo/rpc/model/ModuleModel.java:
##########
@@ -196,4 +197,12 @@ public ConsumerModel registerInternalConsumer(Class<?>
internalService, URL url)
serviceRepository.registerConsumer(consumerModel);
return consumerModel;
}
+
+ public boolean isBindSpring() {
Review Comment:
rename to `isLifeCycleManagedExternally`
##########
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java:
##########
@@ -77,7 +82,44 @@ public void run() {
}
private void doDestroy() {
- applicationModel.destroy();
+ boolean hasModuleBindSpring = false;
+ // check if any modules are bound to Spring
+ for (ModuleModel module: applicationModel.getModuleModels()) {
+ if (module.isBindSpring()) {
+ hasModuleBindSpring = true;
+ break;
+ }
+ }
+ if (hasModuleBindSpring) {
Review Comment:
log out to notice user that dubbo is waiting spring to shutdown
##########
dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/DubboShutdownHook.java:
##########
@@ -77,7 +82,44 @@ public void run() {
}
private void doDestroy() {
- applicationModel.destroy();
+ boolean hasModuleBindSpring = false;
+ // check if any modules are bound to Spring
+ for (ModuleModel module: applicationModel.getModuleModels()) {
+ if (module.isBindSpring()) {
+ hasModuleBindSpring = true;
+ break;
+ }
+ }
+ if (hasModuleBindSpring) {
+ int timeout =
ConfigurationUtils.getServerShutdownTimeout(applicationModel);
+ if (timeout > 0) {
+ long start = System.currentTimeMillis();
+ /**
+ * To avoid shutdown conflicts between Dubbo and Spring,
+ * wait for the modules bound to Spring to be handled by
Spring util timeout.
+ */
+ while (!applicationModel.isDestroyed() && hasModuleBindSpring
+ && (System.currentTimeMillis() - start) < timeout) {
+ try {
+ TimeUnit.MILLISECONDS.sleep(10);
+ hasModuleBindSpring = false;
+ if (!applicationModel.isDestroyed()) {
+ for (ModuleModel module:
applicationModel.getModuleModels()) {
+ if (module.isBindSpring()) {
+ hasModuleBindSpring = true;
+ break;
+ }
+ }
+ }
+ } catch (InterruptedException e) {
+ logger.warn(e.getMessage(), e);
+ }
+ }
+ }
+ }
+ if (!applicationModel.isDestroyed()) {
Review Comment:
log out if wait spring failed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]