AlexStocks commented on code in PR #3099:
URL: https://github.com/apache/dubbo-go/pull/3099#discussion_r2899087303
##########
graceful_shutdown/shutdown.go:
##########
@@ -146,8 +152,17 @@ func beforeShutdown(shutdown *global.ShutdownConfig) {
// destroyRegistries destroys RegistryProtocol directly.
func destroyRegistries() {
logger.Info("Graceful shutdown --- Destroy all registriesConfig. ")
+ // In test environments, the registry protocol might not be registered
+ // Use recover to handle this gracefully
+ defer func() {
+ if r := recover(); r != nil {
+ logger.Warnf("Failed to destroy registries (this is
normal in test environments): %v", r)
+ }
+ }()
registryProtocol := extension.GetProtocol(constant.RegistryProtocol)
- registryProtocol.Destroy()
+ if registryProtocol != nil {
Review Comment:
`extension.GetProtocol`(`common/extension/protocol.go`)未注册时直接
panic,注册时返回具体类型的接口值,永远不会是 nil 接口值。这个 `if registryProtocol \!= nil`
判断是死代码,会误导读者以为 `GetProtocol` 能合法返回 nil。`destroyProtocols` 里同样的问题。
建议:删掉 nil 判断,仅保留 `recover` 即可。
--
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]