Skip to content

fix(options): treat unit durations <= 0 as disabled in ParseURL#3866

Merged
ndyakov merged 1 commit into
redis:masterfrom
sueun-dev:fix-parseurl-duration-disable
Jun 25, 2026
Merged

fix(options): treat unit durations <= 0 as disabled in ParseURL#3866
ndyakov merged 1 commit into
redis:masterfrom
sueun-dev:fix-parseurl-duration-disable

Conversation

@sueun-dev

@sueun-dev sueun-dev commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

ParseURL documents that a duration query parameter is disabled with a value <= 0:

to disable a duration field, use value less than or equal to 0; to use the default value, leave the value blank or remove the parameter

That only works for plain integers. queryOptions.duration() returns the -1 disable sentinel in the integer branch, but a duration written with a unit goes through time.ParseDuration and is returned as-is, so a zero value with a unit is not disabled and falls through to the default:

read_timeout=0          -> ReadTimeout=0   (disabled)
read_timeout=0s         -> ReadTimeout=3s  (default)
conn_max_idle_time=0    -> ConnMaxIdleTime=-1  (disabled)
conn_max_idle_time=0s   -> ConnMaxIdleTime=0   (30m default after init)

(ReadTimeout values are shown after init(), which maps the -1 sentinel to the runtime no-timeout value.)

The fix applies the same <= 0 check in the ParseDuration branch so 0s disables the field like 0 already does. Negative values with a unit (-1s) are normalized to the same -1 sentinel for consistency; those already disabled at runtime since deadline() treats any timeout <= 0 as no deadline, so that part is parse-level consistency rather than a behavior change.

Added two conn_max_idle_time cases (0s, -1s) to TestParseURL; both fail before the change and pass after. go vet ./..., gofmt, and go build ./... are clean. The server-backed suite needs Docker so I did not run it, but the change is confined to URL parsing and is covered by TestParseURL.


Note

Low Risk
Small, localized change to URL option parsing with new unit tests; no auth or connection logic changes beyond correct timeout disable semantics.

Overview
ParseURL duration query params now treat values with units the same as plain integers when disabling timeouts: after time.ParseDuration, dur <= 0 returns the -1 sentinel instead of passing through 0 (which Options.init() would turn into library defaults).

This closes a doc/behavior gap where conn_max_idle_time=0 disabled idle timeout but conn_max_idle_time=0s did not. The same logic applies to other duration URL fields (read_timeout, dial_timeout, etc.).

Tests: TestParseURL adds conn_max_idle_time=0s and conn_max_idle_time=-1s expecting ConnMaxIdleTime: -1.

Reviewed by Cursor Bugbot for commit 5b43405. Bugbot is set up for automated code reviews on this repo. Configure here.

ParseURL documents that a duration query parameter is disabled with a
value <= 0, but queryOptions.duration() applied that rule only to plain
integers. A duration written with a unit went through time.ParseDuration
and was returned as-is, so 0s did not disable the field: read_timeout=0s
fell through to the default instead of disabling like read_timeout=0.

Apply the same <= 0 check in the ParseDuration branch, matching the
plain-integer form, and cover it with two TestParseURL cases
(conn_max_idle_time=0s and =-1s).
@jit-ci

jit-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@ndyakov ndyakov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you @sueun-dev !

@ndyakov ndyakov added the bug label Jun 25, 2026
@ndyakov ndyakov merged commit 39f1625 into redis:master Jun 25, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants