Skip to content

Direct: Refactors OpenTcpConnectionTimeout negative-value warning trace to DocumentClient#5916

Draft
yumnahussain wants to merge 10 commits into
Azure:mainfrom
yumnahussain:users/t-yhussain/move-open-tcp-timeout-warning-trace-to-document-client
Draft

Direct: Refactors OpenTcpConnectionTimeout negative-value warning trace to DocumentClient#5916
yumnahussain wants to merge 10 commits into
Azure:mainfrom
yumnahussain:users/t-yhussain/move-open-tcp-timeout-warning-trace-to-document-client

Conversation

@yumnahussain
Copy link
Copy Markdown
Member

@yumnahussain yumnahussain commented Jun 1, 2026

Follow-up to #5873 addressing @kundadebdatta's comment: move the negative-TimeSpan warning trace out of the CosmosClientOptions.OpenTcpConnectionTimeout setter and into DocumentClient, where the value is consumed.

  • CosmosClientOptions: remove the setter-side DefaultTrace.TraceWarning (and the now-unused Core.Trace using).
  • DocumentClient: emit the warning inside the existing openTcpConnectionTimeout < TimeSpan.Zero branch.
  • ConnectionPolicy / CosmosClientBuilder: XML-doc wording sync.
  • Tests: drop the obsolete setter-warning test; add DocumentClientOpenTcpConnectionTimeoutWarningTests covering negative-emits-warning, truncation-with-warning, setter-silent, non-negative-silent (parameterized), and once-per-construction.
  • Changelog: Unreleased > Other Changes entry (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.

yumnahussain and others added 10 commits May 15, 2026 17:16
…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>
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.

1 participant