From 4a3a2683536b4d46639dc7460846e44f426e5e01 Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Mon, 10 Apr 2023 16:45:41 -0400 Subject: [PATCH] Fix goroutine leak in action install During the install process there was a place where an install process could be stuck trying to write to a channel. This would happen when a context had completed prior to performInstall finishing. In a short running Helm Client this was not a problem. But, for long running applications that use Helm as an SDK there are problems where a memory leak ends up happening due to goroutines never being able to complete. This fix provides a means for performInstall to write to its channel using the method already used to fix the upgrade issue of the same kind. Fixes #11805 Signed-off-by: Matt Farina (cherry picked from commit 7c9d636f40e751c775cd1baea5ef2fd4f7139f6e) --- pkg/action/install.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/action/install.go b/pkg/action/install.go index 4658c9be8b5..9e1d89f0b48 100644 --- a/pkg/action/install.go +++ b/pkg/action/install.go @@ -347,13 +347,17 @@ func (i *Install) RunWithContext(ctx context.Context, chrt *chart.Chart, vals ma return rel, err } rChan := make(chan resultMessage) + ctxChan := make(chan resultMessage) doneChan := make(chan struct{}) defer close(doneChan) go i.performInstall(rChan, rel, toBeAdopted, resources) - go i.handleContext(ctx, rChan, doneChan, rel) - result := <-rChan - //start preformInstall go routine - return result.r, result.e + go i.handleContext(ctx, ctxChan, doneChan, rel) + select { + case result := <-rChan: + return result.r, result.e + case result := <-ctxChan: + return result.r, result.e + } } func (i *Install) performInstall(c chan<- resultMessage, rel *release.Release, toBeAdopted kube.ResourceList, resources kube.ResourceList) {