Direct: Refactors OpenTcpConnectionTimeout negative-value warning trace to DocumentClient#5916
Draft
yumnahussain wants to merge 10 commits into
Conversation
…d and fractional values Fixes Azure#4500. Previously, DocumentClient cast `connectionPolicy.OpenTcpConnectionTimeout.Value.TotalSeconds` directly to int, which silently truncated: * Sub-second values (e.g. `TimeSpan.FromMilliseconds(500)`) to 0, causing the Direct StoreClientFactory to fall back to the request timeout instead of the customer's intent. * Fractional values >= 1s (e.g. `TimeSpan.FromSeconds(2.5)`) down to the next whole second, silently shortening the customer's requested timeout. * Negative values to 0, again silently falling back. This change formalizes the public contract on `CosmosClientOptions.OpenTcpConnectionTimeout`, `ConnectionPolicy.OpenTcpConnectionTimeout`, and `CosmosClientBuilder.WithConnectionModeDirect`: * Negative TimeSpan -> ArgumentOutOfRangeException at the public setter (fail fast). * The customer-supplied TimeSpan is preserved unchanged on the SDK-level properties. * At the int-typed Direct boundary (DocumentClient.cs): * Values in [TimeSpan.Zero, 1 second) normalize to 0 (documented "use request timeout" sentinel). * Values >= 1 second round UP via Math.Ceiling to the nearest whole second so the SDK never silently SHORTENS the customer's requested timeout (e.g. 2.5s -> 3s, never 2s). XML docs on all three public surfaces explicitly call out this contract. Note: the downstream Microsoft.Azure.Cosmos.Direct StoreClientFactory constructor only accepts `int openTimeoutInSeconds` for this parameter, so whole-second resolution at the transport boundary is an external constraint; Math.Ceiling is the closest faithful interpretation of "leave the customer's value unchanged". Tests (CosmosClientOptionsUnitTests): * T1 OpenTcpConnectionTimeout_NegativeTimeSpan_Throws * T2 OpenTcpConnectionTimeout_Zero_IsAllowed_AndRoundTripsThroughConnectionPolicy * T3 OpenTcpConnectionTimeout_SubSecond_NormalizesToZero_InRntbdConfig * T4 OpenTcpConnectionTimeout_WholeSeconds_PreservedInRntbdConfig * T5 WithConnectionModeDirect_NegativeOpenTcpTimeout_Throws * T6 OpenTcpConnectionTimeout_Fractional_RoundsUpInRntbdConfig (2.5s -> 3) * T7 OpenTcpConnectionTimeout_JustOverOneSecond_RoundsUpInRntbdConfig (1.001s -> 2) * T8 OpenTcpConnectionTimeout_Fractional_PreservedOnConnectionPolicyTimeSpan (2.5s round-trips unchanged through ConnectionPolicy) Out of scope: the same (int)TotalSeconds truncation pattern applies to IdleTcpConnectionTimeout at DocumentClient.cs:925. A follow-up issue mirroring Azure#4500 will be filed. Changelog: entry added under Unreleased / Bugs Fixed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… warning log, adds int overflow guard - Negative values now reset to null (transport default 5s) with DefaultTrace.TraceWarning - Removed inline ArgumentOutOfRangeException throws (non-breaking) - Added int.MaxValue clamp to prevent overflow at transport boundary - Simplified ConnectionPolicy.OpenTcpConnectionTimeout to get;set; pattern - Updated tests to verify negative values reset to null - Updated XML docs and changelog Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…fRangeException Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ng-only for backward compatibility - Negative values emit DefaultTrace.TraceWarning but are preserved unchanged - Removes clamping to TimeSpan.Zero and ArgumentOutOfRangeException for negatives - Sub-second values in [0, 1s) explicitly normalize to 0 in DocumentClient - Fractional values >= 1s round up via Math.Ceiling (unchanged) - Updated XML docs, tests, and changelog to reflect warn-only behavior Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Tomas Varon <70857381+tvaron3@users.noreply.github.com>
…ce to DocumentClient Addresses review comment on PR Azure#5873 (kundadebdatta @ CosmosClientOptions.cs:637): client options is not where we typically emit tracing events, so move the negative-TimeSpan warning trace into DocumentClient, the consumer that converts the value into openConnectionTimeoutInSeconds. The trace now fires once at client construction instead of once per setter assignment. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Follow-up to #5873 addressing @kundadebdatta's comment: move the negative-
TimeSpanwarning trace out of theCosmosClientOptions.OpenTcpConnectionTimeoutsetter and intoDocumentClient, where the value is consumed.CosmosClientOptions: remove the setter-sideDefaultTrace.TraceWarning(and the now-unusedCore.Traceusing).DocumentClient: emit the warning inside the existingopenTcpConnectionTimeout < TimeSpan.Zerobranch.ConnectionPolicy/CosmosClientBuilder: XML-doc wording sync.DocumentClientOpenTcpConnectionTimeoutWarningTestscovering negative-emits-warning, truncation-with-warning, setter-silent, non-negative-silent (parameterized), and once-per-construction.Unreleased>Other Changesentry (PR Direct: Fixes OpenTcpConnectionTimeout silent truncation of sub-second and fractional values #5873 already shipped in 3.61.0-preview.0).Stacked on #5873; merge after it lands.