Oxidaner commented on code in PR #3293:
URL: https://github.com/apache/dubbo-go/pull/3293#discussion_r3106762480


##########
server/server.go:
##########
@@ -352,11 +377,50 @@ func (s *Server) Serve() error {
                return err
        }
 
+       s.mu.Lock()
+       s.stopperID = graceful_shutdown.RegisterServerStopper(func(ctx 
context.Context) error {
+               return s.Stop(ctx)
+       })
+       s.mu.Unlock()
+
        // k8s probe ready
        probe.SetStartupComplete(true)
        probe.SetReady(true)
 
-       select {}
+       select {
+       case <-stopCh:
+       case <-graceful_shutdown.Done():
+       }
+
+       return nil
+}
+
+func (s *Server) Stop(ctx context.Context) error {
+       if ctx == nil {
+               ctx = context.Background()
+       }
+
+       s.mu.Lock()
+       stopCh := s.stopCh
+       done := s.serveDone
+       stopperID := s.stopperID
+       if stopCh == nil || done == nil {
+               s.mu.Unlock()
+               return nil
+       }
+       s.stopOnce.Do(func() {
+               close(stopCh)
+       })
+       s.mu.Unlock()
+
+       graceful_shutdown.UnregisterServerStopper(stopperID)
+
+       select {
+       case <-done:
+               return nil
+       case <-ctx.Done():
+               return ctx.Err()
+       }
 }

Review Comment:
   done



##########
graceful_shutdown/shutdown.go:
##########
@@ -130,6 +183,24 @@ func RegisterProtocol(name string) {
        proMu.Unlock()
 }
 
+// Shutdown runs the process-level graceful shutdown orchestration once.
+// Concurrent or repeated callers wait on the same execution result, while 
their
+// own contexts only control how long they wait for that shared run to finish.
+func Shutdown(ctx context.Context) error {
+       if ctx == nil {
+               ctx = context.Background()
+       }
+
+       startShutdownOnce()
+
+       select {
+       case <-shutdownDone:
+               return shutdownResult
+       case <-ctx.Done():
+               return ctx.Err()
+       }
+}

Review Comment:
   done



-- 
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]

Reply via email to