AlexStocks commented on code in PR #3099:
URL: https://github.com/apache/dubbo-go/pull/3099#discussion_r2899088169
##########
graceful_shutdown/shutdown.go:
##########
@@ -124,7 +124,13 @@ func totalTimeout(shutdown *global.ShutdownConfig)
time.Duration {
return timeout
}
-func beforeShutdown(shutdown *global.ShutdownConfig) {
+// BeforeShutdown performs graceful shutdown cleanup including:
+// - Destroying registries
+// - Waiting for active requests to complete
+// - Destroying protocols
+// - Executing custom shutdown callbacks
+// This function can be called manually when InternalSignal is disabled.
+func BeforeShutdown(shutdown *global.ShutdownConfig) {
Review Comment:
原来 `beforeShutdown` 是私有函数,只在 `Init` 的 goroutine 里调用一次。导出为 `BeforeShutdown`
后,`server.go` 可以直接调用,而 `Init` 内部的 goroutine(`InternalSignal=true` 时)也会调用。两次
`destroyRegistries()` + `destroyProtocols()` 会对已销毁的资源重复操作(double free
语义),行为未定义。虽然 `server.go` 靠 `InternalSignal` 判断来规避,但这依赖调用者自律。
建议:加 `sync.Once` 保证无论被谁调用多少次,只执行一次。
--
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]