Skip to content

Commit c641ff7

Browse files
Enable query timeout of 20 seconds (#1038)
1 parent 6f6bacf commit c641ff7

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

internal/internal_utils.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const (
6161
minRPCTimeout = 1 * time.Second
6262
//maxRPCTimeout is maximum rpc call timeout allowed
6363
maxRPCTimeout = 5 * time.Second
64+
// maxQueryRPCTimeout is the maximum rpc call timeout allowed for query
65+
maxQueryRPCTimeout = 20 * time.Second
6466
)
6567

6668
var (
@@ -99,8 +101,17 @@ func chanTimeout(timeout time.Duration) func(builder *contextBuilder) {
99101
}
100102
}
101103

104+
// newChannelContext - Get a rpc channel context for query
105+
func newChannelContextForQuery(ctx context.Context, options ...func(builder *contextBuilder)) (context.Context, context.CancelFunc, []yarpc.CallOption) {
106+
return newChannelContextHelper(ctx, true, options...)
107+
}
108+
102109
// newChannelContext - Get a rpc channel context
103110
func newChannelContext(ctx context.Context, options ...func(builder *contextBuilder)) (context.Context, context.CancelFunc, []yarpc.CallOption) {
111+
return newChannelContextHelper(ctx, false, options...)
112+
}
113+
114+
func newChannelContextHelper(ctx context.Context, isQuery bool, options ...func(builder *contextBuilder)) (context.Context, context.CancelFunc, []yarpc.CallOption) {
104115
rpcTimeout := defaultRPCTimeout
105116
if ctx != nil {
106117
// Set rpc timeout less than context timeout to allow for retries when call gets lost
@@ -110,8 +121,10 @@ func newChannelContext(ctx context.Context, options ...func(builder *contextBuil
110121
// Make sure to not set rpc timeout lower than minRPCTimeout
111122
if rpcTimeout < minRPCTimeout {
112123
rpcTimeout = minRPCTimeout
113-
} else if rpcTimeout > maxRPCTimeout {
124+
} else if rpcTimeout > maxRPCTimeout && !isQuery {
114125
rpcTimeout = maxRPCTimeout
126+
} else if rpcTimeout > maxQueryRPCTimeout && isQuery {
127+
rpcTimeout = maxQueryRPCTimeout
115128
}
116129
}
117130
}

internal/internal_workflow_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ func (wc *workflowClient) QueryWorkflowWithOptions(ctx context.Context, request
915915
var resp *s.QueryWorkflowResponse
916916
err := backoff.Retry(ctx,
917917
func() error {
918-
tchCtx, cancel, opt := newChannelContext(ctx)
918+
tchCtx, cancel, opt := newChannelContextForQuery(ctx)
919919
defer cancel()
920920
var err error
921921
resp, err = wc.workflowService.QueryWorkflow(tchCtx, req, opt...)

0 commit comments

Comments
 (0)