VOL-4697: Fixes for rolling update case
Change-Id: Idce67b7752386b5fbe985564933bb510dc0e4bd0
diff --git a/VERSION b/VERSION
index f2c6cb6..cf78d5b 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-4.2.3
+4.2.4
diff --git a/cmd/openolt-adapter/main.go b/cmd/openolt-adapter/main.go
index cffd2ab..5fcb2c7 100644
--- a/cmd/openolt-adapter/main.go
+++ b/cmd/openolt-adapter/main.go
@@ -205,8 +205,10 @@
timeout := a.config.LiveProbeInterval / 2
kvStoreChannel := make(chan bool, 1)
- // Default false to check the liveliness.
- kvStoreChannel <- false
+ timeoutCtx, cancelFunc := context.WithTimeout(ctx, 2*time.Second)
+ kvStoreChannel <- a.kvClient.IsConnectionUp(timeoutCtx)
+ cancelFunc()
+
for {
timeoutTimer := time.NewTimer(timeout)
select {
@@ -220,10 +222,12 @@
probe.UpdateStatusFromContext(ctx, kvService, probe.ServiceStatusRunning)
timeout = a.config.LiveProbeInterval / 2
}
+
// Check if the timer has expired or not
if !timeoutTimer.Stop() {
<-timeoutTimer.C
}
+
case <-timeoutTimer.C:
// Check the status of the kv-store. Use timeout of 2 seconds to avoid forever blocking
logger.Info(ctx, "kv-store liveliness-recheck")
@@ -258,7 +262,7 @@
logger.Infow(ctx, "fail-to-release-all-reservations", log.Fields{"error": err})
}
// Close the DB connection
- a.kvClient.Close(ctx)
+ go a.kvClient.Close(ctx)
}
if a.eventProxy != nil {
@@ -274,6 +278,8 @@
a.coreClient.Stop(ctx)
}
+ logger.Info(ctx, "main-stop-processing-complete")
+
// TODO: Stop child devices connections
// TODO: More cleanup
@@ -534,8 +540,12 @@
code := waitForExit(ctx)
logger.Infow(ctx, "received-a-closing-signal", log.Fields{"code": code})
+ // Use context with cancel as etcd-client stop could take more time sometimes to stop slowing down container shutdown.
+ ctxWithCancel, cancelFunc := context.WithCancel(ctx)
// Cleanup before leaving
- ad.stop(ctx)
+ ad.stop(ctxWithCancel)
+ // Will halt any long-running stop routine gracefully
+ cancelFunc()
elapsed := time.Since(start)
logger.Infow(ctx, "run-time", log.Fields{"instanceId": ad.config.InstanceID, "time": elapsed / time.Second})