Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions service/matching/physical_task_queue_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/rand/v2"
"strings"
"sync"
"sync/atomic"
"time"
Expand All @@ -30,6 +31,7 @@ import (
"go.temporal.io/server/common/testing/testhooks"
"go.temporal.io/server/common/worker_versioning"
"go.temporal.io/server/service/matching/counter"
"go.temporal.io/server/service/worker/workerdeployment"
"google.golang.org/protobuf/types/known/durationpb"
)

Expand Down Expand Up @@ -725,6 +727,9 @@ func (c *physicalTaskQueueManagerImpl) ensureRegisteredInDeploymentVersion(
}
var errResourceExhausted *serviceerror.ResourceExhausted
if !errors.As(err, &errResourceExhausted) {
if strings.Contains(err.Error(), workerdeployment.ErrTooManyDeploymentsInNamespacePrefix) {
return err
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unreachable code: check is inside wrong conditional branch

The new check for ErrTooManyDeploymentsInNamespacePrefix is placed inside the if !errors.As(err, &errResourceExhausted) block, meaning it only executes when the error is NOT a *serviceerror.ResourceExhausted. However, the "too many deployments" error is created via newResourceExhaustedError() which returns a *serviceerror.ResourceExhausted. Therefore, errors.As will return true for this error, the condition !errors.As(...) will be false, and this new code block will never execute for the intended error case. The check needs to be moved outside or before the !errors.As conditional.

Fix in Cursor Fix in Web

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Unreachable code: check is inside wrong conditional branch

The new check for ErrTooManyDeploymentsInNamespacePrefix is placed inside the if !errors.As(err, &errResourceExhausted) block, meaning it only executes when the error is NOT a *serviceerror.ResourceExhausted. However, the "too many deployments" error is created via newResourceExhaustedError() which returns a *serviceerror.ResourceExhausted. Therefore, errors.As will return true for this error, the condition !errors.As(...) will be false, and this new code block will never execute for the intended error case. The check needs to be moved outside or before the !errors.As conditional.

Fix in Cursor Fix in Web

// Do not surface low level error to user
c.logger.Error("error while registering version", tag.Error(err))
err = errDeploymentVersionNotReady
Expand Down
2 changes: 1 addition & 1 deletion service/worker/workerdeployment/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,7 @@ func (d *ClientImpl) updateWithStartWorkerDeployment(
}
limit := d.maxDeployments(namespaceEntry.Name().String())
if count >= int64(limit) {
return nil, newResourceExhaustedError(fmt.Sprintf("reached maximum deployments in namespace (%d)", limit))
return nil, newResourceExhaustedError(fmt.Sprintf(errTooManyDeploymentsInNamespace, limit))
}
}

Expand Down
2 changes: 2 additions & 0 deletions service/worker/workerdeployment/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const (
ErrManagerIdentityMismatch = "ManagerIdentity '%s' is set and does not match user identity '%s'; to proceed, set your own identity as the ManagerIdentity, remove the ManagerIdentity, or wait for the other client to do so"
ErrWorkerDeploymentNotFound = "no Worker Deployment found with name '%s'; does your Worker Deployment have pollers?"
ErrWorkerDeploymentVersionNotFound = "build ID '%s' not found in Worker Deployment '%s'"
ErrTooManyDeploymentsInNamespacePrefix = "reached maximum worker deployments in namespace"
errTooManyDeploymentsInNamespace = ErrTooManyDeploymentsInNamespacePrefix + " (%d)"
)

var (
Expand Down
Loading