long poll timeout constants (#10246)

## What changed?

Introduces shared constants for default long poll timeout/buffer and
applies them to SAA and SANO.

## Why?

After a long internal technical discussion, 60s was determined as the
default for the timeout.
This commit is contained in:
Stephan Behnke
2026-05-14 13:50:08 -07:00
committed by GitHub
parent 48c1530736
commit 4be69e5f46
4 changed files with 16 additions and 13 deletions

View File

@@ -1,9 +1,8 @@
package activity
import (
"time"
"go.temporal.io/server/chasm/lib/callback"
"go.temporal.io/server/common"
"go.temporal.io/server/common/dynamicconfig"
"go.temporal.io/server/common/retrypolicy"
)
@@ -17,13 +16,13 @@ var (
LongPollTimeout = dynamicconfig.NewNamespaceDurationSetting(
"activity.longPollTimeout",
20*time.Second,
common.DefaultLongPollTimeout,
`Timeout for activity long-poll requests.`,
)
LongPollBuffer = dynamicconfig.NewNamespaceDurationSetting(
"activity.longPollBuffer",
time.Second,
common.DefaultLongPollBuffer,
`A buffer used to adjust the activity long-poll timeouts.
Specifically, activity long-poll requests are timed out at a time which leaves at least the buffer's duration
remaining before the caller's deadline, if permitted by the caller's deadline.`,

View File

@@ -6,6 +6,7 @@ import (
"text/template"
"time"
"go.temporal.io/server/common"
"go.temporal.io/server/common/backoff"
"go.temporal.io/server/common/config"
"go.temporal.io/server/common/dynamicconfig"
@@ -15,14 +16,14 @@ import (
var LongPollTimeout = dynamicconfig.NewNamespaceDurationSetting(
"nexusoperation.longPollTimeout",
20*time.Second,
common.DefaultLongPollTimeout,
`Maximum timeout for nexus operation long-poll requests. Actual wait may be shorter to leave
longPollBuffer before the caller deadline.`,
)
var LongPollBuffer = dynamicconfig.NewNamespaceDurationSetting(
"nexusoperation.longPollBuffer",
time.Second,
common.DefaultLongPollBuffer,
`A buffer used to adjust the nexus operation long-poll timeouts.
Specifically, nexus operation long-poll requests are timed out at a time which leaves at least the buffer's duration
remaining before the caller's deadline, if permitted by the caller's deadline.`,

View File

@@ -31,10 +31,16 @@ const (
)
const (
// MinLongPollTimeout is the minimum context timeout for long poll API, below which
// the request won't be processed
// DefaultLongPollTimeout is the default context timeout for a long poll request.
DefaultLongPollTimeout = time.Second * 60
// DefaultLongPollBuffer is the buffer used to adjust a long poll request timeout.
// Specifically, long poll requests are timed out at a time which leaves at least the buffer's duration
// remaining before the caller's deadline, if permitted by the caller's deadline.
DefaultLongPollBuffer = time.Second
// MinLongPollTimeout is the minimum context timeout for a long poll request, below which
// the request won't be processed.
MinLongPollTimeout = time.Second * 2
// CriticalLongPollTimeout is a threshold for the context timeout passed into long poll API,
// CriticalLongPollTimeout is a threshold for the context timeout passed into a long poll request,
// below which a warning will be logged
CriticalLongPollTimeout = time.Second * 10
)

View File

@@ -3,7 +3,6 @@ package api
import (
"context"
"fmt"
"time"
commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
@@ -25,8 +24,6 @@ import (
historyi "go.temporal.io/server/service/history/interfaces"
)
const longPollSoftTimeout = time.Second
//nolint:revive // cognitive complexity 39 (> max enabled 25)
func GetOrPollWorkflowMutableState(
ctx context.Context,
@@ -191,7 +188,7 @@ func GetOrPollWorkflowMutableState(
// Send back response just before caller context would time out.
longPollInterval := shardContext.GetConfig().LongPollExpirationInterval(namespaceRegistry.Name().String())
longPollCtx, cancel := contextutil.WithDeadlineBuffer(ctx, longPollInterval, longPollSoftTimeout)
longPollCtx, cancel := contextutil.WithDeadlineBuffer(ctx, longPollInterval, common.DefaultLongPollBuffer)
defer cancel()
for {