From 235b1ae23f6ad4d26dc56063c95358145e937c09 Mon Sep 17 00:00:00 2001 From: James Munson Date: Wed, 23 Oct 2024 21:17:14 -0600 Subject: [PATCH] fix(upgrade): add short sleep to allow shutdown and event to flush before panic Signed-off-by: James Munson --- app/post_upgrade.go | 6 +++++- app/pre_upgrade.go | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/app/post_upgrade.go b/app/post_upgrade.go index 6e69e958d6..21d3971236 100644 --- a/app/post_upgrade.go +++ b/app/post_upgrade.go @@ -70,7 +70,11 @@ func postUpgrade(c *cli.Context) error { if err != nil { return errors.Wrap(err, "failed to create event broadcaster") } - defer eventBroadcaster.Shutdown() + defer func() { + eventBroadcaster.Shutdown() + // Allow a little time for the event to flush, but not greatly delay response to the calling job. + time.Sleep(5 * time.Second) + }() scheme := runtime.NewScheme() if err := longhorn.SchemeBuilder.AddToScheme(scheme); err != nil { diff --git a/app/pre_upgrade.go b/app/pre_upgrade.go index 8bb26527d1..e304351dbd 100644 --- a/app/pre_upgrade.go +++ b/app/pre_upgrade.go @@ -1,6 +1,8 @@ package app import ( + "time" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -61,7 +63,11 @@ func preUpgrade(c *cli.Context) error { if err != nil { return errors.Wrap(err, "failed to create event broadcaster") } - defer eventBroadcaster.Shutdown() + defer func() { + eventBroadcaster.Shutdown() + // Allow a little time for the event to flush, but not greatly delay response to the calling job. + time.Sleep(5 * time.Second) + }() scheme := runtime.NewScheme() if err := longhorn.SchemeBuilder.AddToScheme(scheme); err != nil {