From 1d80c0633a87d2a1830832953ef1f98fe6ad9357 Mon Sep 17 00:00:00 2001 From: Liran BG Date: Wed, 7 Sep 2022 09:09:36 +0300 Subject: [PATCH] IG-21104 - verify ctx cancelled to avoid sending on closed channel (#56) --- pkg/dlx/resourcestarter.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/dlx/resourcestarter.go b/pkg/dlx/resourcestarter.go index 6a66221..5b231ca 100644 --- a/pkg/dlx/resourcestarter.go +++ b/pkg/dlx/resourcestarter.go @@ -139,6 +139,15 @@ func (r *ResourceStarter) waitResourceReadiness(ctx context.Context, resourceReadyChannel chan error) { err := r.scaler.SetScaleCtx(ctx, []scaler_types.Resource{resource}, 1) + + // callee decided to cancel, the resourceReadyChannel is already closed, + // so we can just return without sending anything + if errors.RootCause(ctx.Err()) == context.Canceled || ctx.Err() == context.Canceled { + r.logger.WarnWithCtx(ctx, + "Wait resource readiness canceled", + "resourceName", resource.Name) + return + } resourceReadyChannel <- err }