Skip to content

fix(retry): correct retry_max_wait < retry_min_wait instead of panicking (#214) - #233

Merged
vikrantpuppala merged 1 commit into
mainfrom
fix/214-retry-backoff-bound-correction
Aug 10, 2026
Merged

vikrantpuppala merged 1 commit into
mainfrom
fix/214-retry-backoff-bound-correction

Conversation

@vikrantpuppala

Copy link
Copy Markdown
Collaborator

Summary

Fixes ERRORRECOV-014 (#214): a backoff-bound tuning typo where retry_max_wait < retry_min_wait was not corrected. The session opened fine, but the first retry panicked in calculate_backoff — wait.clamp(config.min_wait, config.max_wait) hits Duration's Ord::clamp, which asserts min <= max (assertion failed: min <= max). On a transient 503 this aborted the caller's task with an unhandleable panic instead of returning a Result — strictly worse than an open-time error.

Per the shared spec and the reference ODBC driver (databricks-odbc#181), the correct behavior is to correct the pair (raise max to min) with a warning, not reject or panic — a backoff bound is a tuning hint. This matches the clamp-and-warn discipline apply_client_result_overrides already uses for cloudfetch_max_chunks_in_memory.

Changes

  • src/client/retry.rs — calculate_backoff: uses an effective ceiling max_wait.max(min_wait) in both the Retry-After clamp and the exponential-backoff cap, so no config can panic it. Silent on this per-retry hot path.
  • src/session.rs — build_retry_configs_for_session: emits the one-time correction warn! and raises max to min when building the per-session RetryConfig (the single per-session build point, so no log spam).
  • src/c_abi/session.rs — kernel_session_config_set_retry_config: now corrects-and-warns instead of rejecting max_wait_ms < min_wait_ms with InvalidArgument, aligning the C-ABI with the Rust path and the reference driver. The min_wait_ms == 0 rejection is kept (a zero floor is genuinely invalid, not a correctable typo).

Test plan

  • New regression test_calculate_backoff_max_below_min_does_not_panic (src/client/retry.rs): with min_wait=3s, max_wait=1s, asserts calculate_backoff does not panic and returns >= min_wait for both the Retry-After path and the exponential path. Confirmed it panics on the pre-fix code and passes after.
  • Updated C-ABI test set_retry_config_rejects_zero_min_corrects_bad_range (was set_retry_config_rejects_bad_range): min_wait_ms == 0 still returns InvalidArgument; max_wait_ms(1s) < min_wait_ms(5s) now returns Success with the stored RetrySpec having max_wait == min_wait == 5s.
  • cargo +stable fmt --all, cargo clippy --all-targets -- -D warnings, and cargo test all pass (748 lib tests, 0 failures).
  • End-to-end tripwire lives in the coverage repo (databricks-driver-test#1110, retry_wait_max_below_min_is_corrected_not_fatal): the session opens with retry_wait_min=3s / retry_wait_max=1s, then a 503+Retry-After retry succeeds without panicking. That xfail flips green once this lands.

Note on the sibling finding #185 (ERRORRECOV-013)

The related transport-error-retry finding is handled separately (a comment on #185, no code change here): the kernel already retries the provably-safe is_connect() transport failures on ExecuteStatement, and the mid-flight-close scenario is an ambiguous case that would risk double-executing non-idempotent SQL — which the kernel declines by policy. This PR does not close #185.

This pull request and its description were written by Isaac.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues identified by the review bot.

…ing (#214)

A backoff-bound tuning typo where `retry_max_wait < retry_min_wait` was
dormant until the first retry, then panicked in `calculate_backoff`:
`wait.clamp(min_wait, max_wait)` hits `Duration`'s `Ord::clamp`, which
asserts `min <= max`. On a transient 503 this aborted the caller's task
with an unhandleable panic instead of returning a `Result`.

Correct the pair (raise max to min) with a warning, rather than reject or
panic — a backoff bound is a tuning hint, matching the clamp-and-warn
discipline `apply_client_result_overrides` already uses:

- `calculate_backoff` now uses an effective ceiling `max_wait.max(min_wait)`
  so no config can panic it (silent on this per-retry hot path).
- `build_retry_configs_for_session` emits the one-time correction `warn!`
  and raises max to min when building the per-session `RetryConfig`.
- C-ABI `kernel_session_config_set_retry_config` now corrects-and-warns
  instead of rejecting `max_wait_ms < min_wait_ms` with `InvalidArgument`,
  aligning it with the Rust path and the reference ODBC driver. The
  `min_wait_ms == 0` rejection stays (a zero floor is genuinely invalid).

Closes #214

This pull request and its description were written by Isaac.

Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ No issues identified by the review bot.

@vikrantpuppala
vikrantpuppala added this pull request to the merge queue Aug 10, 2026
Merged via the queue into main with commit 9d2e59b Aug 10, 2026
18 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — 8fccb4c7 Deployed Aug 10, 2026 by vikrantpuppala via followup #245
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.

[coverage] Conformance findings: ERRORRECOV-013

1 participant