From 6b2e44863dea9d571f56ec4cf52cf3c5dc5c53e9 Mon Sep 17 00:00:00 2001 From: Yichao Yang Date: Thu, 29 Dec 2022 12:32:02 -0800 Subject: [PATCH] Fix NPE in task channelWeightFn (#3766) --- service/history/queues/scheduler.go | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/service/history/queues/scheduler.go b/service/history/queues/scheduler.go index 8b5cc767f48..b84cb9747f1 100644 --- a/service/history/queues/scheduler.go +++ b/service/history/queues/scheduler.go @@ -33,6 +33,7 @@ import ( "go.temporal.io/server/common/clock" "go.temporal.io/server/common/dynamicconfig" "go.temporal.io/server/common/log" + "go.temporal.io/server/common/log/tag" "go.temporal.io/server/common/metrics" "go.temporal.io/server/common/namespace" "go.temporal.io/server/common/quotas" @@ -114,14 +115,25 @@ func NewNamespacePriorityScheduler( } channelWeightFn := func(key TaskChannelKey) int { namespaceWeights := options.ActiveNamespaceWeights + namespaceName := namespace.EmptyName - namespace, _ := namespaceRegistry.GetNamespaceByID(namespace.ID(key.NamespaceID)) - if !namespace.ActiveInCluster(currentClusterName) { - namespaceWeights = options.StandbyNamespaceWeights + namespace, err := namespaceRegistry.GetNamespaceByID(namespace.ID(key.NamespaceID)) + if err == nil { + namespaceName = namespace.Name() + if !namespace.ActiveInCluster(currentClusterName) { + namespaceWeights = options.StandbyNamespaceWeights + } + } else { + // if namespace not found, treat is as active namespace and + // use default active namespace weight + logger.Warn("Unable to find namespace, using active namespace task channel weight", + tag.WorkflowNamespaceID(key.NamespaceID), + tag.Error(err), + ) } return configs.ConvertDynamicConfigValueToWeights( - namespaceWeights(namespace.Name().String()), + namespaceWeights(namespaceName.String()), logger, )[key.Priority] }