Skip to content

Commit adf7c54

Browse files
authored
Fix NPE in task channelWeightFn (#3766)
1 parent 98545f9 commit adf7c54

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

service/history/queues/scheduler.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"go.temporal.io/server/common/clock"
3434
"go.temporal.io/server/common/dynamicconfig"
3535
"go.temporal.io/server/common/log"
36+
"go.temporal.io/server/common/log/tag"
3637
"go.temporal.io/server/common/metrics"
3738
"go.temporal.io/server/common/namespace"
3839
"go.temporal.io/server/common/quotas"
@@ -114,14 +115,25 @@ func NewNamespacePriorityScheduler(
114115
}
115116
channelWeightFn := func(key TaskChannelKey) int {
116117
namespaceWeights := options.ActiveNamespaceWeights
118+
namespaceName := namespace.EmptyName
117119

118-
namespace, _ := namespaceRegistry.GetNamespaceByID(namespace.ID(key.NamespaceID))
119-
if !namespace.ActiveInCluster(currentClusterName) {
120-
namespaceWeights = options.StandbyNamespaceWeights
120+
namespace, err := namespaceRegistry.GetNamespaceByID(namespace.ID(key.NamespaceID))
121+
if err == nil {
122+
namespaceName = namespace.Name()
123+
if !namespace.ActiveInCluster(currentClusterName) {
124+
namespaceWeights = options.StandbyNamespaceWeights
125+
}
126+
} else {
127+
// if namespace not found, treat is as active namespace and
128+
// use default active namespace weight
129+
logger.Warn("Unable to find namespace, using active namespace task channel weight",
130+
tag.WorkflowNamespaceID(key.NamespaceID),
131+
tag.Error(err),
132+
)
121133
}
122134

123135
return configs.ConvertDynamicConfigValueToWeights(
124-
namespaceWeights(namespace.Name().String()),
136+
namespaceWeights(namespaceName.String()),
125137
logger,
126138
)[key.Priority]
127139
}

0 commit comments

Comments
 (0)