Skip to content

Conversation

wprzytula
Copy link
Collaborator

Problem statement

The implementation of request timeouts set on statement/batch is hand-crafted and independent from the Rust Driver-provided request timeouts set on cluster/execution profile. This is obviously incorrect, as a longer request timeout on statement/batch would not override a shorter timeout set on cluster/execution profile.

Solution

This PR leverages the MaybeUnsetConfig framework to work with request timeouts, and fixes statements and batches to use the Rust Driver's built-in request timeout capabilities.
Care is taken to support the semantics correctly:

  • timeout = 0 means that there should be no timeout. As the Rust driver does not allow for such setting on the statement/batch level, it is emulated using an extremely long timeout.
  • timeout = u64::MAX means that the timeout should be unset (and the execution profile's/cluster's setting should be used instead). This corresponds to passing None to the Rust Driver's {Statement,Batch}::set_request_timeout.

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have implemented Rust unit tests for the features/changes introduced.
  • [ ] I have enabled appropriate tests in Makefile in {SCYLLA,CASSANDRA}_(NO_VALGRIND_)TEST_FILTER.
  • [ ] I added appropriate Fixes: annotations to PR description.

wprzytula added 3 commits July 8, 2025 11:30
Adds implementation of RequestTimeout as a `MaybeUnsetConfigValue` type,
allowing it to be used in the same way as other config values that can
be unset.
Request timeout handling in `cass_statement_set_request_timeout` was
broken: it was implemented by hand, which meant that it did not
cooperate with execution profiles. In particular, if someone set
a longer timeout on a statement than the one set in the execution
profile, then the execution profile's timeout was still used.

This commit fixes this by using the dedicated Rust Driver Statement's
API for setting the request timeout, which correctly cooperates with
execution profiles (including the cluster's default request timeout).
Request timeout handling in `cass_batch_set_request_timeout` was
broken:
1. It was implemented by hand, which meant that it did not
cooperate with execution profiles. In particular, if someone set
a longer timeout on a statement than the one set in the execution
profile, then the execution profile's timeout was still used.
2. It did not handle the `0` value correctly - it was interpreted
as a request timeout of 0 milliseconds, while it should be interpreted
as "no timeout".

This commit fixes both problems.
@wprzytula wprzytula added this to the 0.5.1 milestone Jul 8, 2025
@wprzytula wprzytula requested review from Lorak-mmk and Copilot July 8, 2025 09:52
@wprzytula wprzytula self-assigned this Jul 8, 2025
@wprzytula wprzytula added the bug Something isn't working label Jul 8, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR replaces hand-crafted per-statement and per-batch timeout handling with the Rust driver’s built-in timeout API, using the MaybeUnsetConfig framework to correctly interpret zero, max, and unset values.

  • Introduces a new RequestTimeout type and conversion logic in config_value.rs
  • Updates cass_statement_set_request_timeout and cass_batch_set_request_timeout to call the driver’s set_request_timeout with the right semantics
  • Removes manual storage of timeout values and tokio::timeout wrappers in session.rs

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
scylla-rust-wrapper/src/config_value.rs Added RequestTimeout and infallible C-value conversion
scylla-rust-wrapper/src/statement.rs Hooked into driver’s set_request_timeout, removed old field
scylla-rust-wrapper/src/batch.rs Same update for batches
scylla-rust-wrapper/src/session.rs Deleted custom timeout futures and related fields
Comments suppressed due to low confidence (2)

scylla-rust-wrapper/src/config_value.rs:113

  • Add unit tests for RequestTimeout to verify that C values 0, MAX, and typical values map to the intended Option<Duration> outcomes.
pub(crate) struct RequestTimeout(pub(crate) Option<Duration>);

scylla-rust-wrapper/src/config_value.rs:112

  • [nitpick] Consider adding a doc comment on RequestTimeout to explain its semantics (how zero → infinite, MAX → unset, and other values).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

@wprzytula wprzytula mentioned this pull request Jul 8, 2025
6 tasks
@wprzytula wprzytula merged commit ffa7a9e into scylladb:master Jul 8, 2025
16 of 17 checks passed
@wprzytula wprzytula deleted the fix-statement-request-timeouts branch July 8, 2025 13:20
@wprzytula wprzytula mentioned this pull request Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants