Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upgrade): add sleep to allow event to flush before panic #3234

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/post_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember you used a big number before. How do you determine the sleep period?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The long period was to allow a shot at gathering logs before the pod exited. But as @PhanLe1010 points out, that could get in the way of another run, and if the event is in place, the logs are not as important. This is a reasonable guess at a time that should allow the event to be flushed, but get the result back to the job quickly.

Copy link
Member

@derekbit derekbit Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@james-munson Isee.
Ah, no, I mean leave a comment above time.Sleep(5 * time.Second). Thank you.

}()

scheme := runtime.NewScheme()
if err := longhorn.SchemeBuilder.AddToScheme(scheme); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion app/pre_upgrade.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package app

import (
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
Expand Down Expand Up @@ -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 {
Expand Down