Fix context cancellation issue (#2212)

This commit is contained in:
Emmanuel Keller 2023-07-05 14:30:44 +01:00 committed by GitHub
parent 2b9fe88342
commit 67687496c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 20 deletions

View file

@ -79,16 +79,16 @@ impl Iterator {
// Log the statement
trace!("Iterating: {}", stm);
// Enable context override
let mut run = Context::new(ctx);
self.run = run.add_cancel();
let mut cancel_ctx = Context::new(ctx);
self.run = cancel_ctx.add_cancel();
// Process the query LIMIT clause
self.setup_limit(ctx, opt, stm).await?;
self.setup_limit(&cancel_ctx, opt, stm).await?;
// Process the query START clause
self.setup_start(ctx, opt, stm).await?;
self.setup_start(&cancel_ctx, opt, stm).await?;
// Process any EXPLAIN clause
let explanation = self.output_explain(ctx, opt, stm)?;
let explanation = self.output_explain(&cancel_ctx, opt, stm)?;
// Process prepared values
self.iterate(ctx, opt, stm).await?;
self.iterate(&cancel_ctx, opt, stm).await?;
// Return any document errors
if let Some(e) = self.error.take() {
return Err(e);

View file

@ -15,7 +15,6 @@ struct Prefix<'a> {
pub tb: &'a str,
_d: u8,
pub ix: &'a str,
_e: u8,
}
impl<'a> Prefix<'a> {
@ -30,7 +29,6 @@ impl<'a> Prefix<'a> {
tb,
_d: CHAR_INDEX,
ix,
_e: b'*',
}
}
}
@ -46,9 +44,7 @@ struct PrefixIds<'a> {
pub tb: &'a str,
_d: u8,
pub ix: &'a str,
_e: u8,
pub fd: Array,
_f: u8,
}
impl<'a> PrefixIds<'a> {
@ -63,9 +59,7 @@ impl<'a> PrefixIds<'a> {
tb,
_d: CHAR_INDEX,
ix,
_e: b'*',
fd: fd.to_owned(),
_f: b'*',
}
}
}
@ -81,9 +75,7 @@ pub struct Index<'a> {
pub tb: &'a str,
_d: u8,
pub ix: &'a str,
_e: u8,
pub fd: Array,
_f: u8,
pub id: Option<Id>,
}
@ -141,9 +133,7 @@ impl<'a> Index<'a> {
tb,
_d: CHAR_INDEX,
ix,
_e: 0x2a, // *
fd,
_f: 0x2a, // *
id,
}
}

View file

@ -898,18 +898,17 @@ async fn define_statement_index_multiple_unique_existing() -> Result<(), Error>
}
//
let tmp = res.remove(0).result;
println!("{:?}", tmp);
assert!(matches!(
tmp.err(),
Some(e) if e.to_string() == r#"Database index `test` already contains ['tesla', 'test@surrealdb.com'], with record `user:4`"#
Some(e) if e.to_string() == r#"Database index `test` already contains ['apple', 'test@surrealdb.com'], with record `user:3`"#
));
//
let tmp = res.remove(0).result;
assert!(matches!(
tmp.err(),
Some(e) if e.to_string() == r#"Database index `test` already contains ['tesla', 'test@surrealdb.com'], with record `user:4`"#
Some(e) if e.to_string() == r#"Database index `test` already contains ['apple', 'test@surrealdb.com'], with record `user:3`"#
));
//
let tmp = res.remove(0).result?;
let val = Value::parse(
"{