Skip to content

Ignore non-positive values for interval dynamic configs - #12671

Open
A-RYAN-1 wants to merge 4 commits into
temporalio:mainfrom
A-RYAN-1:fix/12652-dynconfig-nonpositive-intervals
Open

A-RYAN-1 wants to merge 4 commits into
temporalio:mainfrom
A-RYAN-1:fix/12652-dynconfig-nonpositive-intervals

Conversation

@A-RYAN-1

@A-RYAN-1 A-RYAN-1 commented Oct 22, 2026 •

Copy link
Copy Markdown

What changed?

Added a general validation hook for dynamic config settings: WithValidation(convert, validators...) wraps any converter so the converted value must also pass each Validator[T], and Positive is the first validator. It plugs into the existing New*TypedSettingWithConverter and New*TypedSettingWithConstrainedDefault constructors, so it works for every precedence and value type without new generated constructors. A rejected value behaves like an unparseable one: the collection logs a throttled warning and uses the next matching value or the default, and the YAML loader reports it as invalid.

Applied WithValidation(convertDuration, Positive[time.Duration]) to nine of the ten settings listed in the issue: system.clusterMetadataRefreshInterval, system.namespaceCacheRefreshInterval, matching.updateAckInterval, matching.getUserDataRefresh, matching.nexusEndpointsRefreshInterval, history.timerProcessorUpdateAckInterval, history.archivalProcessorUpdateAckInterval, history.timerProcessorMaxPollInterval and history.archivalProcessorMaxPollInterval. history.shardUpdateMinInterval is left alone: its only readers add it to a timestamp (context_impl.go), so 0 there means "update every time" and nothing spins or panics.

Why?

Setting any of these to 0 does not disable the work: it panics a ticker, spins a loop with no pause, or runs the work hundreds of times more often. Fixes #12652.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

New tests in collection_test.go cover zero and negative values written as ints, durations, strings and floats on a global setting, a zero override on the task queue setting with constrained defaults, every validated key rejecting 0 through Validate, and WithValidation with several validators including NaN. The two collection tests fail on the base commit. go test ./common/dynamicconfig/ passes.

Potential risks

A deployment that currently relies on 0 for one of these nine settings will now get the default instead, with a warning in the log. All other settings are unchanged.

@A-RYAN-1
A-RYAN-1 requested review from a team as code owners October 22, 2026 04:32
@CLAassistant

CLAassistant commented Oct 22, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@0xamlab

0xamlab commented Oct 22, 2026

Copy link
Copy Markdown

Verified on dc30900 with go1.27.1: go test -tags test_dep ./common/dynamicconfig/... passes, 147 tests, 0 failures, including both new positive-duration subtests. Also checked the production key directly: with system.clusterMetadataRefreshInterval set to 0, ClusterMetadataRefreshInterval.Get() returns 0s on main (e8ee627) and 1m0s, the default, on this branch. That 0s reaches time.NewTicker at common/cluster/metadata.go:394 and panics with "non-positive interval for NewTicker". The d <= 0 rejection at common/dynamicconfig/setting_positive_duration.go:15 is what blocks it.

@A-RYAN-1

Copy link
Copy Markdown
Author

The CLA is signed and the new tests pass, and an outside check on Go 1.27 confirmed them. Could a maintainer take a first look when there is time? Happy to change anything.

Setting an interval dynamic config to 0 does not disable the work it
configures. Depending on the setting it panics a ticker, spins a loop
with no pause, or runs the work hundreds of times more often.

Add positive-duration setting constructors whose converter rejects
values <= 0. The collection already handles a conversion error by
logging a throttled warning and using the default, so a mistaken 0 now
falls back to the default instead of taking effect.

Use them for clusterMetadataRefreshInterval, namespaceCacheRefreshInterval,
matching.updateAckInterval, matching.getUserDataRefresh,
matching.nexusEndpointsRefreshInterval, the timer and archival processor
update-ack and max-poll intervals, and history.shardUpdateMinInterval.
@A-RYAN-1
A-RYAN-1 force-pushed the fix/12652-dynconfig-nonpositive-intervals branch from dc30900 to 0bf4bd7 Compare October 24, 2026 06:24
@A-RYAN-1

Copy link
Copy Markdown
Author

Rebased onto main (the only conflict was next to the new EnableWorkflowEagerDispatchCheck setting in constants.go), and the dynamicconfig tests pass. A first review is welcome whenever there is time. Thank you.

@A-RYAN-1

Copy link
Copy Markdown
Author

Rebased onto main with the Temporal CLA signed and checks green. A review from the dynamic config owners would be welcome, and I can change the validation approach if you prefer.

@dnr dnr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This approach isn't going to scale, we need a more flexible API for defining settings with configurable validations.

@A-RYAN-1

Copy link
Copy Markdown
Author

Thanks, reworked along those lines. The one-off positive-duration constructors are gone: WithValidation(convert, validators...) now wraps any converter with composable Validator[T] checks, and Positive is just the first validator, usable with any setting type and precedence. I also dropped history.shardUpdateMinInterval because 0 is meaningful there (no throttling). Happy to change the shape again if you had something different in mind.

@A-RYAN-1

A-RYAN-1 commented Nov 1, 2026

Copy link
Copy Markdown
Author

Reworked after the review into a general WithValidation(convert, validators...) plus Positive (3b6c0d0), nine settings, tests fail on the base. Would appreciate a re-review when you have time.

@0xamlab

0xamlab commented Nov 7, 2026

Copy link
Copy Markdown

Rechecked 3b6c0d061 with Go 1.27.1: go test -tags test_dep ./common/dynamicconfig/... -count=1 passes. A focused runtime probe of system.clusterMetadataRefreshInterval resolved 7s to 7s; 0 and -7s failed validation and both resolved to the 1m0s default. history.shardUpdateMinInterval=0 still validates and resolves to 0s, so the timestamp check at service/history/shard/context_impl.go:1245 imposes no delay. The suite also exercises WithValidation with multiple validators on an integer setting, beyond the duration use case.

@A-RYAN-1

A-RYAN-1 commented Nov 9, 2026

Copy link
Copy Markdown
Author

Thanks @0xamlab for rechecking the latest commit. @dnr the WithValidation plus Positive rework is in place and has now had an independent check; could you take another look when you have time?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Several dynamic config intervals have no guard against 0 value

4 participants