Skip to content

Commit

Permalink
remove validator on context timeout value in matching side (#2445)
Browse files Browse the repository at this point in the history
* remove validator on context timeout value in matching side
  • Loading branch information
yux0 committed Aug 27, 2019
1 parent ae63ef7 commit 38fa525
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gen/go/admin/admin.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gen/go/cadence/cadence.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gen/go/health/health.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gen/go/history/history.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gen/go/indexer/indexer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gen/go/matching/matching.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gen/go/replicator/replicator.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gen/go/shared/shared.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .gen/go/sqlblobs/sqlblobs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 25 additions & 7 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,15 +424,16 @@ func CheckEventBlobSizeLimit(actualSize, warnLimit, errorLimit int, domainID, wo
// ValidateLongPollContextTimeout check if the context timeout for a long poll handler is too short or below a normal value.
// If the timeout is not set or too short, it logs an error, and return ErrContextTimeoutNotSet or ErrContextTimeoutTooShort
// accordingly. If the timeout is only below a normal value, it just logs an info and return nil.
func ValidateLongPollContextTimeout(ctx context.Context, handlerName string, logger log.Logger) error {
deadline, ok := ctx.Deadline()
if !ok {
err := ErrContextTimeoutNotSet
logger.Error("Context timeout not set for long poll API.",
tag.WorkflowHandlerName(handlerName), tag.Error(err))
func ValidateLongPollContextTimeout(
ctx context.Context,
handlerName string,
logger log.Logger,
) error {

deadline, err := ValidateLongPollContextTimeoutIsSet(ctx, handlerName, logger)
if err != nil {
return err
}

timeout := deadline.Sub(time.Now())
if timeout < MinLongPollTimeout {
err := ErrContextTimeoutTooShort
Expand All @@ -447,6 +448,23 @@ func ValidateLongPollContextTimeout(ctx context.Context, handlerName string, log
return nil
}

// ValidateLongPollContextTimeoutIsSet checks if the context timeout is set for long poll requests.
func ValidateLongPollContextTimeoutIsSet(
ctx context.Context,
handlerName string,
logger log.Logger,
) (time.Time, error) {

deadline, ok := ctx.Deadline()
if !ok {
err := ErrContextTimeoutNotSet
logger.Error("Context timeout not set for long poll API.",
tag.WorkflowHandlerName(handlerName), tag.Error(err))
return deadline, err
}
return deadline, nil
}

// GetSizeOfMapStringToByteArray get size of map[string][]byte
func GetSizeOfMapStringToByteArray(input map[string][]byte) int {
if input == nil {
Expand Down
4 changes: 2 additions & 2 deletions service/matching/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (h *Handler) PollForActivityTask(ctx context.Context,
return nil, h.handleErr(errMatchingHostThrottle, scope)
}

if err := common.ValidateLongPollContextTimeout(
if _, err := common.ValidateLongPollContextTimeoutIsSet(
ctx,
"PollForActivityTask",
h.Service.GetThrottledLogger(),
Expand Down Expand Up @@ -221,7 +221,7 @@ func (h *Handler) PollForDecisionTask(ctx context.Context,
return nil, h.handleErr(errMatchingHostThrottle, scope)
}

if err := common.ValidateLongPollContextTimeout(
if _, err := common.ValidateLongPollContextTimeoutIsSet(
ctx,
"PollForDecisionTask",
h.Service.GetThrottledLogger(),
Expand Down

0 comments on commit 38fa525

Please sign in to comment.