Alanxtl commented on code in PR #1133:
URL: https://github.com/apache/dubbo-go-samples/pull/1133#discussion_r3787937911
##########
graceful_shutdown/go-server/cmd/main.go:
##########
@@ -64,44 +80,96 @@ func (p *GreetProvider) Greet(ctx context.Context, req
*greet.GreetRequest) (*gr
return resp, nil
}
+func (p *GreetProvider) triggerShutdownOnFirstGreet() {
+ if !p.shutdownOnFirstGreet {
+ return
+ }
+
+ p.shutdownOnce.Do(func() {
+ go func() {
+ time.Sleep(200 * time.Millisecond)
+ p.holdRejectProbeWindow()
+ proc, err := os.FindProcess(os.Getpid())
+ if err != nil {
+ panic(fmt.Sprintf("failed to find current
process for shutdown trigger: %v", err))
+ }
+ if err := proc.Signal(os.Interrupt); err != nil {
+ panic(fmt.Sprintf("failed to trigger graceful
shutdown: %v", err))
+ }
+ logger.Info("Triggered graceful shutdown after first
greet request entered provider")
+ }()
+ })
+}
+
+func (p *GreetProvider) holdRejectProbeWindow() {
+ if p.rejectProbeWindow <= 0 || p.shutdownConfig == nil {
+ return
+ }
+
+ p.shutdownConfig.ConsumerActiveCount.Inc()
+ logger.Infof("Holding graceful shutdown reject stage for integration
probe, window=%s", p.rejectProbeWindow)
+ go func() {
+ time.Sleep(p.rejectProbeWindow)
+ p.shutdownConfig.ConsumerActiveCount.Dec()
+ logger.Info("Released graceful shutdown reject stage
integration probe window")
+ }()
+}
+
func main() {
port := flag.Int("port", 20000, "triple listen port")
timeout := flag.Duration("timeout", 60*time.Second, "overall graceful
shutdown timeout budget")
stepTimeout := flag.Duration("step-timeout", 3*time.Second, "timeout
for waiting provider and consumer in-flight requests")
+ notifyTimeout := flag.Duration("notify-timeout", 5*time.Second,
"timeout for notifying consumers during graceful shutdown")
consumerUpdateWait := flag.Duration("consumer-update-wait",
3*time.Second, "time to wait for consumers to observe instance changes")
offlineWindow := flag.Duration("offline-window", 3*time.Second, "time
window for observing late requests after offline")
requestDelay := flag.Duration("delay", 0, "artificial delay added to
each greet request")
+ ignoreContextCancel := flag.Bool("ignore-context-cancel", false,
"continue the artificial delay even if the request context is canceled")
+ shutdownOnFirstGreet := flag.Bool("shutdown-on-first-greet", false,
"trigger graceful shutdown after the first greet request enters the provider")
+ rejectProbeWindow := flag.Duration("reject-probe-window", 0, "keep the
framework reject stage open long enough for an integration probe")
flag.Parse()
- graceful_shutdown.Init(
+ shutdownConfig := graceful_shutdown.NewOptions(
graceful_shutdown.WithTimeout(*timeout),
graceful_shutdown.WithStepTimeout(*stepTimeout),
+ graceful_shutdown.WithNotifyTimeout(*notifyTimeout),
graceful_shutdown.WithConsumerUpdateWaitTime(*consumerUpdateWait),
graceful_shutdown.WithOfflineRequestWindowTimeout(*offlineWindow),
- )
- logger.Infof("Graceful shutdown initialized, timeout=%s step-timeout=%s
consumer-update-wait=%s offline-window=%s request-delay=%s",
- timeout.String(), stepTimeout.String(),
consumerUpdateWait.String(), offlineWindow.String(), requestDelay.String())
+ ).Shutdown
- srv, err := server.NewServer(
- server.WithServerProtocol(
+ ins, err := dubbo.NewInstance(
+
dubbo.WithShutdown(graceful_shutdown.SetShutdownConfig(shutdownConfig)),
+ dubbo.WithProtocol(
protocol.WithProtocol("tri"),
protocol.WithPort(*port),
protocol.WithID("tri"),
),
)
Review Comment:
为啥又改成了这样初始化 直接dubbo.WithShutdown不行吗
##########
.github/workflows/github-actions.yml:
##########
@@ -66,7 +66,7 @@ jobs:
run: |
set -euo pipefail
if [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
- BRANCH=${{ github.base_ref }}
Review Comment:
这个不要改
--
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]