Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break long poll loop early when context remaining timeout is too low #1123

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var _ DomainClient = (*domainClient)(nil)
const (
defaultDecisionTaskTimeoutInSecs = 10
defaultGetHistoryTimeoutInSecs = 25
minLongPollInterval = 100 * time.Millisecond
)

var (
Expand Down Expand Up @@ -512,6 +513,15 @@ func (wc *workflowClient) GetWorkflowHistory(
var err error
Loop:
for {
// Stop polling the server if the remaining context timeout is too low.
// This prevents unnessesary final call which will result in a timeout anyway.
if deadline, ok := ctx.Deadline(); ok {
remainingTime := deadline.Sub(time.Now())
if remainingTime < minLongPollInterval {
return nil, context.DeadlineExceeded
}
}

err = backoff.Retry(ctx,
func() error {
var err1 error
Expand Down