You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/09/22 01:33:14 UTC

[GitHub] [dubbo-go] LaurenceLiZhixin commented on a change in pull request #1470: feat(*): add graceful shutdown

LaurenceLiZhixin commented on a change in pull request #1470:
URL: https://github.com/apache/dubbo-go/pull/1470#discussion_r713527026



##########
File path: config/graceful_shutdown.go
##########
@@ -51,61 +54,49 @@ import (
 const defaultShutDownTime = time.Second * 60
 
 // nolint
-//func GracefulShutdownInit() {
-//	signals := make(chan os.Signal, 1)
-//
-//	signal.Notify(signals, ShutdownSignals...)
-//
-//	// retrieve ShutdownConfig for gracefulShutdownFilter
-//	if filter, ok := extension.GetFilter(constant.GracefulShutdownConsumerFilterKey).(config.Setter); ok && config.GetConsumerConfig().ShutdownConfig != nil {
-//		filter.Set(config.GracefulShutdownFilterShutdownConfig, config.GetConsumerConfig().ShutdownConfig)
-//	}
-//	if filter, ok := extension.GetFilter(constant.GracefulShutdownProviderFilterKey).(config.Setter); ok && config.GetProviderConfig().ShutdownConfig != nil {
-//		filter.Set(config.GracefulShutdownFilterShutdownConfig, config.GetProviderConfig().ShutdownConfig)
-//	}
-//
-//	go func() {
-//		select {
-//		case sig := <-signals:
-//			logger.Infof("get signal %s, applicationConfig will shutdown.", sig)
-//			// gracefulShutdownOnce.Do(func() {
-//			time.AfterFunc(totalTimeout(), func() {
-//				logger.Warn("Shutdown gracefully timeout, applicationConfig will shutdown immediately. ")
-//				os.Exit(0)
-//			})
-//			BeforeShutdown()
-//			// those signals' original behavior is exit with dump ths stack, so we try to keep the behavior
-//			for _, dumpSignal := range DumpHeapShutdownSignals {
-//				if sig == dumpSignal {
-//					debug.WriteHeapDump(os.Stdout.Fd())
-//				}
-//			}
-//			os.Exit(0)
-//		}
-//	}()
-//}
+func GracefulShutdownInit() {
+	signals := make(chan os.Signal, 1)
+
+	signal.Notify(signals, ShutdownSignals...)
+
+	// retrieve ShutdownConfig for gracefulShutdownFilter
+	if filter, ok := extension.GetFilter(constant.GracefulShutdownConsumerFilterKey).(Setter); ok && rootConfig.Shutdown != nil {
+		filter.Set(constant.GracefulShutdownFilterShutdownConfig, rootConfig.Shutdown)
+	}
+
+	go func() {
+		select {
+		case sig := <-signals:
+			logger.Infof("get signal %s, applicationConfig will shutdown.", sig)
+			// gracefulShutdownOnce.Do(func() {
+			time.AfterFunc(totalTimeout(), func() {
+				logger.Warn("Shutdown gracefully timeout, applicationConfig will shutdown immediately. ")
+				os.Exit(0)
+			})
+			BeforeShutdown()
+			// those signals' original behavior is exit with dump ths stack, so we try to keep the behavior
+			for _, dumpSignal := range DumpHeapShutdownSignals {
+				if sig == dumpSignal {
+					debug.WriteHeapDump(os.Stdout.Fd())
+				}
+			}
+			os.Exit(0)
+		}
+	}()
+}
 
 // BeforeShutdown provides processing flow before shutdown
 func BeforeShutdown() {
 	destroyAllRegistries()
 	// waiting for a short time so that the clients have enough time to get the notification that server shutdowns
 	// The value of configuration depends on how long the clients will get notification.
-	//waitAndAcceptNewRequests()
-
-	// reject the new request, but keeping waiting for accepting requests
-	//waitForReceivingRequests()
-
-	// we fetch the protocols from Consumer.References. Consumer.ProtocolConfig doesn't contains all protocol, like jsonrpc
-	//consumerProtocols := getConsumerProtocols()
-
-	// If this applicationConfig is not the provider, it will do nothing
-	//destroyProviderProtocols(consumerProtocols)
+	waitAndAcceptNewRequests()
 
-	// reject sending the new request, and waiting for response of sending requests
-	//waitForSendingRequests()
+	// reject sending/receiving the new request, but keeping waiting for accepting requests
+	waitForSendingAndReceivingRequests()
 
-	// If this applicationConfig is not the consumer, it will do nothing
-	//destroyConsumerProtocols(consumerProtocols)
+	// destroy all protocols
+	destroyProtocols()
 

Review comment:
       可否在这里加上metadata report的销毁?




-- 
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: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org