diff --git a/pkg/action/upgrade.go b/pkg/action/upgrade.go index a4a1a0883..1e7054118 100644 --- a/pkg/action/upgrade.go +++ b/pkg/action/upgrade.go @@ -321,11 +321,17 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR return nil, err } rChan := make(chan resultMessage) + ctxChan := make(chan resultMessage) + doneChan := make(chan interface{}) go u.releasingUpgrade(rChan, upgradedRelease, current, target, originalRelease) - go u.handleContext(ctx, rChan, upgradedRelease) - result := <-rChan - - return result.r, result.e + go u.handleContext(ctx, doneChan, ctxChan, upgradedRelease) + select { + case result := <-rChan: + doneChan <- true + return result.r, result.e + case result := <-ctxChan: + return result.r, result.e + } } // Function used to lock the Mutex, this is important for the case when the atomic flag is set. @@ -341,13 +347,17 @@ func (u *Upgrade) reportToPerformUpgrade(c chan<- resultMessage, rel *release.Re } // Setup listener for SIGINT and SIGTERM -func (u *Upgrade) handleContext(ctx context.Context, c chan<- resultMessage, upgradedRelease *release.Release) { - +func (u *Upgrade) handleContext(ctx context.Context, done chan interface{}, c chan<- resultMessage, upgradedRelease *release.Release) { go func() { - <-ctx.Done() - err := ctx.Err() - // when the atomic flag is set the ongoing release finish first and doesn't give time for the rollback happens. - u.reportToPerformUpgrade(c, upgradedRelease, kube.ResourceList{}, err) + select { + case <-ctx.Done(): + err := ctx.Err() + + // when the atomic flag is set the ongoing release finish first and doesn't give time for the rollback happens. + u.reportToPerformUpgrade(c, upgradedRelease, kube.ResourceList{}, err) + case <-done: + return + } }() } func (u *Upgrade) releasingUpgrade(c chan<- resultMessage, upgradedRelease *release.Release, current kube.ResourceList, target kube.ResourceList, originalRelease *release.Release) {