chia7712 commented on code in PR #811:
URL: https://github.com/apache/yunikorn-k8shim/pull/811#discussion_r1546925324


##########
pkg/dispatcher/dispatcher.go:
##########
@@ -257,13 +260,23 @@ func Stop() {
        }
 
        close(getDispatcher().stopChan)
-       maxTimeout := 5
-       for getDispatcher().isRunning() && maxTimeout > 0 {
-               log.Log(log.ShimDispatcher).Info("waiting for dispatcher to be 
stopped",
-                       zap.Int("remainingSeconds", maxTimeout))
-               time.Sleep(1 * time.Second)
-               maxTimeout--
+       stopWait := make(chan struct{})
+       defer close(stopWait)
+
+       go func() {
+               getDispatcher().stopped.Wait()
+               stopWait <- struct{}{}

Review Comment:
   > That would mean double closure
   
   pardon me. why it causes double closure if we remove the `close(stopWait)` 
from `Stop()`.
   
   ```go
        stopWait := make(chan struct{})
           // defer close(stopWait) move this into goroutine
   
        go func() {
                defer close(stopWait)
                getDispatcher().stopped.Wait()
        }()
   
        // wait until the main event loop stops properly
        select {
        case <-stopWait:
                break
        case <-time.After(5 * time.Second):
                log.Log(log.ShimDispatcher).Info("dispatcher did not stop in 
time")
                break
        }
   ```



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

Reply via email to