Skip to content

Commit 50873fa

Browse files
committed
session: Add a trait to guard against bad ResT in run_query
run_query, execute_query, etc have a template type called ResT. There was a bug where ResT was set to QueryResponse, which could be an error response. This was not caught by retry policy which assumed all errors would come from analyzing Result<ResT, QueryError>. (#501) This trait is a guard to make sure that this mistake doesn't happen again. All ResT uses must be validated by implementing this trait. Signed-off-by: Jan Ciolek <[email protected]>
1 parent 96dfa58 commit 50873fa

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

scylla/src/transport/session.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,7 @@ impl Session {
10841084
where
10851085
ConnFut: Future<Output = Result<Arc<Connection>, QueryError>>,
10861086
QueryFut: Future<Output = Result<ResT, QueryError>>,
1087+
ResT: AllowedRunQueryResTType,
10871088
{
10881089
let cluster_data = self.cluster.get_data();
10891090
let query_plan = self.load_balancer.plan(&statement_info, &cluster_data);
@@ -1176,6 +1177,7 @@ impl Session {
11761177
where
11771178
ConnFut: Future<Output = Result<Arc<Connection>, QueryError>>,
11781179
QueryFut: Future<Output = Result<ResT, QueryError>>,
1180+
ResT: AllowedRunQueryResTType,
11791181
{
11801182
let mut last_error: Option<QueryError> = None;
11811183

@@ -1283,6 +1285,7 @@ impl Session {
12831285
) -> Result<ResT, QueryError>
12841286
where
12851287
QueryFut: Future<Output = Result<ResT, QueryError>>,
1288+
ResT: AllowedRunQueryResTType,
12861289
{
12871290
let info = Statement::default();
12881291
let config = StatementConfig {
@@ -1375,3 +1378,18 @@ async fn resolve_hostname(hostname: &str) -> Result<SocketAddr, NewSessionError>
13751378

13761379
ret.ok_or(failed_err)
13771380
}
1381+
1382+
// run_query, execute_query, etc have a template type called ResT.
1383+
// There was a bug where ResT was set to QueryResponse, which could
1384+
// be an error response. This was not caught by retry policy which
1385+
// assumed all errors would come from analyzing Result<ResT, QueryError>.
1386+
// This trait is a guard to make sure that this mistake doesn't
1387+
// happen again.
1388+
// When using run_query make sure that the ResT type is NOT able
1389+
// to contain any errors.
1390+
// See https://github.com/scylladb/scylla-rust-driver/issues/501
1391+
pub trait AllowedRunQueryResTType {}
1392+
1393+
impl AllowedRunQueryResTType for Uuid {}
1394+
impl AllowedRunQueryResTType for BatchResult {}
1395+
impl AllowedRunQueryResTType for NonErrorQueryResponse {}

0 commit comments

Comments
 (0)