Skip to content

Apply timeout flags after merge so explicit zero disables the timeout - #51

Open
Robbie1977 wants to merge 1 commit into
mayth:v2from
Robbie1977:fix-read-timeout-zero-no-timeout
Open

Apply timeout flags after merge so explicit zero disables the timeout#51
Robbie1977 wants to merge 1 commit into
mayth:v2from
Robbie1977:fix-read-timeout-zero-no-timeout

Conversation

@Robbie1977

Copy link
Copy Markdown

Fixes #50.

Problem

In ParseConfig, mergo.Merge(&config, configFromFlags, mergo.WithOverride) does not override a destination field when the source field is a zero value. An explicit -read_timeout 0 parses to the zero value — indistinguishable from an unset flag — so it never overrides the non-zero default ReadTimeout (15s). The documented behaviour "zero or negative value means no timeout" was therefore only reachable with a negative duration; 0 silently fell back to 15s, cutting long uploads at 15s.

Fix

After the flag merge, re-apply the read/write timeout flags directly when the user actually provided them, using flag.Visit. This mirrors the existing IsSet() handling used for the bool flags. An explicit 0 now disables the timeout as documented; an unset flag keeps the default.

Behaviour

args before after
(unset) 15s 15s
-read_timeout 0 15s 0 (no timeout)
-read_timeout=-1s -1s -1s
-read_timeout 30s 30s 30s

Testing

go build ./... and gofmt are clean, and go test ./... passes. Verified the four cases above with a table test against ParseConfig.

mergo.Merge with WithOverride does not override a destination field with a
zero-value source field. An explicit `-read_timeout 0` parses to the zero
value, which is indistinguishable from an unset flag, so it never overrode
the non-zero default ReadTimeout (15s). The documented behaviour "zero or
negative value means no timeout" was therefore only reachable with a
negative duration.

Re-apply the read/write timeout flags directly after the flag merge when
the user actually provided them, using flag.Visit, so an explicit 0
disables the timeout as documented while an unset flag keeps the default.
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.

-read_timeout 0 does not disable the read timeout; only a negative value works (contradicts flag help)

1 participant