Skip to content

Commit

Permalink
Fix NPE in task channelWeightFn (#3766)
Browse files Browse the repository at this point in the history
  • Loading branch information
yycptt committed Dec 29, 2022
1 parent ff3f95c commit 6b2e448
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions service/history/queues/scheduler.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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]
}
Expand Down

0 comments on commit 6b2e448

Please sign in to comment.