Apply timeout flags after merge so explicit zero disables the timeout - #51
Open
Robbie1977 wants to merge 1 commit into
Open
Apply timeout flags after merge so explicit zero disables the timeout#51Robbie1977 wants to merge 1 commit into
Robbie1977 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 0parses to the zero value — indistinguishable from an unset flag — so it never overrides the non-zero defaultReadTimeout(15s). The documented behaviour "zero or negative value means no timeout" was therefore only reachable with a negative duration;0silently 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 existingIsSet()handling used for the bool flags. An explicit0now disables the timeout as documented; an unset flag keeps the default.Behaviour
-read_timeout 0-read_timeout=-1s-read_timeout 30sTesting
go build ./...andgofmtare clean, andgo test ./...passes. Verified the four cases above with a table test againstParseConfig.